How to programmatically select items during rs.Command?

I’m trying to use the SelBoundary command in a macro and/or script, but I can’t figure out how to select the boundary curve just once… When I call the command from python, it stops to wait for an input and won’t let me use rs.SelectObject to continue. That wouldn’t be ideal if I want to do the script in batches. I ran into this problem before too when I was trying to use Squish in python. What am I missing, or is there another way to go about this?


IIRC, you will need to name the boundary curve (can do that in the script) then select it by name in the command string using SelName… Or maybe you can just use SelID with the object id gotten from GetObject(). Edit - yes, SelID works.

import rhinoscriptsyntax as rs

msg="Select closed curve to use as a selection boundary"
if obj_id:
    comm_str="_SelBoundary _SelectionMode=_Window  _Precise=_Yes _SelID {}"
1 Like

Perfect, thanks! Nice formatting too btw. I didn’t make the connection that you could use .format() on a variable lol.

It worked for adding object arrays to the command as well.

obj_str = ""
for obj in objects:
    obj_str += "_SelId {} ".format(obj)

cmd_str = "_Squish _SelID {} {} _Enter"
rs.Command(cmd_str.format(srf, obj_str))