[python] How to script a command that requires multiple inputs?

Like say _-Squish. How can I pass the selected objects when rs.Command() accepts just a string?

You’re going to need to either preselect the objects (for only one set) before rs.Command() or monkey around with grouping/naming the various selection sets and scripting SelName/SelGroup in your command string…

Ah, so I can pass on the name as string to append the command string.
Thanks, didn’t think of that.

But how would it work with group/multiple objects? It’s a list of objects, or am I wrong?

Update:
I don’t understand the idea, rs.ObjectsByName or rs.ObjectsByLayer they all return GUID as string. But commands do not accept guids

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc


poly_id = rs.GetObject(message="Get'em!: ", filter=rs.filter.polysurface)
crvs_ids = rs.GetObjects(message="Get'em all!: ", filter=rs.filter.curve, group=True, preselect=True, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None)

rs.Command("_-Squish {0} {1} _Enter _S _No _P _Yes _D _Free _M _Floppy _O _Up _E _Yes _Enter".format(poly_id,crvs_ids[0]))

#rs.SelectObject(objs_ids)rs.SelectObject(poly_id)
#rs.ObjectsByLayer

_SelID ?

1 Like

Nice one, didn’t know it existed.

But now…how can I break the rs.Command("_-Squish"....) in order to start _SelD and then continue with the Squish :thinking:

image

Mitch advised pre-selection. I use it a lot too, so I don’t have to figure out a more “neat” code.

SelID = selid

1 Like

pre-selection doesn’t work, there is no way to add the objects if the command has multiple inputs (selections).

Oh God :man_facepalming:

You’re right, the command cancels your selection. Hey there’s always RhinoScript for that thing. :slight_smile:

No Squish method in RhinoCommon that I could find :wink: This is why I turned to scripted commands I usually tend to avoid them.

My last resort, turned to be ship graveyard. :smiley:

I’m going crazy :crazy_face:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc


poly_id = rs.GetObject(message="Get'em!: ", filter=rs.filter.polysurface)
crvs_ids = rs.GetObjects(message="Get'em all!: ", filter=rs.filter.curve+rs.filter.polysurface+rs.filter.surface, group=True, preselect=True, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None)

list = ["_SelID {0} _Enter".format(crvs_ids[i]) for i in range(len(crvs_ids))]
com_string = "_-Squish _SelID {0} _Enter _Enter {1} _Enter _Enter _S _No _P _Yes _D _Free _M _Floppy _O _Up _E _Yes _Enter _Enter".format(poly_id,list)


com_string = com_string.replace("['","")
com_string = com_string.replace("', '"," ")
com_string = com_string.replace("']","")

print com_string

rs.Command(com_string)


Could you replace this with ” “.join(my_list)
list is a reserved word…

Thanks for the hint @Dancergraham,

Nevertheless, something doesn’t work.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc


poly_id = rs.GetObject(message="Get'em!: ", filter=rs.filter.polysurface)
crvs_ids = rs.GetObjects(message="Get'em all!: ", filter=rs.filter.curve+rs.filter.polysurface+rs.filter.surface, group=True, preselect=True, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None)

slist = ["_SelID {0} _Enter".format(crvs_ids[i]) for i in range(len(crvs_ids))]
#print len(slist)

stri = " ".join(slist)

#print stri
com_string = "_-Squish _SelID {0} _Enter _Enter {1} _Enter _Enter _S _No _P _Yes _D _Free _M _Floppy _O _Up _E _Yes _Enter _Enter".format(poly_id,stri)

print com_string

rs.Command(com_string)


image

I get No objects added to selection.

You didn’t read my previous post carefully enough. I am not talking about rs.ObjectsByName() or similar methods, I am talking about scripting the command -SelName “name” or -SelGroup “group” in your command string so that you can select multiple items in different stages of command execution.

Like this on the file below to subtract all the red boxes (object name redboxes) fromm the green boxes (group name greenboxes).

import rhinoscriptsyntax as rs
commstr="BooleanDifference -SelGroup {} Enter -SelName {} Enter".format("greenboxes","redboxes")
rs.Command(commstr)

redgreenboxes.3dm (848.7 KB)

1 Like

That is correct, I’m sorry. I was multitasking back then.

I still couldn’t do it this way, though. I was selecting the polysurface and I guess I need the face here (same as the unroll command)

Something interesting that I’ve found: :wink:
image

Update:
pre-selecting the face before launching this (below) does the trick, almost:

com_string = "_-Squish _Enter -SelGroup Group01 _Enter"
print com_string

rs.Command(com_string)

Yes, but you are running one command, just specifying the options. You can’t do that with several lines as far as I know, it needs to be one long string.

Most of the selection stuff is not guaranteed to work with sub-objects (when scripting commands), I think you would need to extract those as discrete objects (faces to surfaces, edges to curves, etc.) before running the command string and perhaps delete them later.