When using Rino.Command("-_SomeCommand"), how can I find what parameters a given command expects? I’m sure this must be clearly documented for all the commands somewhere, but I can’t seem to find it.
Hi Edmark- the Rhino Help file will explain the various options, and it can be useful for more complex commands to run the command in MacroEditor as well, applying the options as you see them turn up on the command line until it works the way you want, then use that as a guide to the Rhino.Command input.
I assume this is what you mean by the “Rhino Help file”:
I am not finding it helpful for writing commands, since it is aimed at those using the GUI, not those writing commands. How can I figure out what exactly I should be including on the command line? (So far, the only way I’ve been able to do this is to invoke a command from a script and note what parameters the command asks for, but this is extremely cumbersome, and I can’t always get it to work, since it seems to default to previous values sometimes unless I restart Rhino.)
Also, I’m running on Mac OS, so, as I understand it, there is no MacroEditor available to me. Or am I mistaken about this?
There is some info in a thread [here] - imported from the old Python forum. In my experience the only way to do this is trial-and-error, you have a much better shot at this in Windows with its command line than you have on a Mac. My method is to run the command “manually” first in Rhino to see what order the options need to be scripted, then run successive test scripts and use F2 to bring up command history to see where it is failing.
: Export as .3ds from python
Is there really no documentation for commands, outlining the options and their required order? How can this be? I’m having a very hard and frustrating time trying to figure out what options are needed by running the command “manually”. I managed to get this to work:
rs.Command("-_Insert Node1 O D 0,0,0 1.0 0")
which places the objects at the origin at 1:1 scale with no rotation. But I don’t understand what the “D” is doing. And I also don’t understand the resulting command history:
Rotation angle <0.000> ( AxisAlign ReferencePoint ) -_Insert
Name of block to insert ( File=No ) Node1
Insert as ( Block Group Objects ) O
Import scaling: Keep ( DimensionNumbers ) D
Insertion point ( Rotate Scale ) 0,0,0
Scale factor <1.000> ( ReferencePoint XYZ Rotate ) 1.0
Rotation angle <0.000> ( AxisAlign ReferencePoint ) 0
Is there documentation for how to interpret Command histories? Do some of these represent default values? Or choices? e.g. What does “( ReferencePoint XYZ Rotate )” represent?
I have failed at my attempt to insert the file contents as a block–I’ve only been able to get it to insert as objects. I can’t seem to find any combination of options that will produce an acceptable script for blocks.
Is what I am trying to do completely esoteric?
I would think you want the following:
import rhinoscriptsyntax as rs rs.Command("-_Insert Node1 _Block 0,0,0 1.0 0")
If Rhino knows the path to the file (like there is a search path set to the file location or something)…
import rhinoscriptsyntax as rs Node1="C:\\Users\\yourname\\Desktop\\Node1" #sample file path rs.Command("-_Insert "+Node1+" _Block 0,0,0 1.0 0")
where the sample file path is the full path to the file referenced by the variable Node1.
If you are not doing rotation or scaling, you do not need to worry about “DimensionNumbers”; also typing “O” will insert as an object, not a block. I prefer to spell out all options fully for clarity, and also with an underscore so that they will work if the script has to run on a system in another language.
Here is a sample where the object is rotated 90° and scaled by 2 (around the origin, if you wanted different points also possible with still more options…)
rs.Command("-_Insert Node1 _Block _Rotate 90 _Scale 2 0,0,0")
Thank you, Mitch! This is a BIG help!
How did you figure out that you need to use the identifiers “_Rotate” and “_Scale” to identify those options, but don’t have to use anything to identify the location? I was surprised to find that I can change the order of _Rotate and _Scale, presumably because they are clearly identified by their name (or is it because they both show up at the same time in the command options popup?). Is there no such name for the location option?
Well, the Insert command is particularly twisted to script - most stuff is easier. What I did is precisely what I said - I created a test script and a file to insert and started testing. The first thing I did was to try to insert the test file manually using the dash version of the command to get an overview of all the options. That gave me the following:
Command: -Insert Name of block to insert ( File=No ): File=Yes Name of file to insert ( File=Yes LinkMode=Embed Browse ): Browse Insert as <Block> ( Block Group Objects ): Insertion point ( Rotate Scale ): 0 Scale factor <1.000> ( ReferencePoint XYZ Rotate ): Rotation angle <0.000> ( AxisAlign ReferencePoint ):
Now, anything in parentheses above is a command line option, and they can have sub-options as well. The order in which the stuff happens is important. So, note that where it asks for the insertion point, there are Rotate and Scale options available. These need to be done BEFORE the insertion point - as the command will move forward if you give it the insertion point first. So I then expanded one (Rotate) to see:
Insertion point ( Rotate Scale ): Rotate Rotation angle <0.000> ( AxisAlign ReferencePoint Move Scale ):
Note here that the Rotate option has sub-options including Scale - so you can do Rotate and then invoke Scale after. You can also do it in the inverse order… Also I think I was incorrect in saying that you can choose the point around which the object rotates or scales - it appears to be always the origin of the file being imported.
I know this seems pretty complicated - as I said in general scripting with rs.Command is a bit tricky and the more levels of options you have the worse it gets… Insert appears to be one of the worst-case scenarios…
Thanks once again, Mitch. Very helpful!
Through trial-and-error I’m getting a little more clarity about how to construct the arguments, but it’s very slow going. I finally figured out (I think) that things like “File=Yes” and “LinkMode=Embed” are single parameter values. Based on that I got the below command to compile and run:
rs.Command("-_Insert _File=_Yes _LinkMode=_Link Node1 _Block _Scale 1 _Rotate 90 0,0,0")
The only problem is that the “LinkMode=Link” doesn’t seem to be working. When I query the nature of the Block I inserted
rs.IsBlockEmbedded() returns True and
rs.IsBlockReference() returns False, which is just the opposite of what I would expect.
Any idea what I’m doing wrong here?
I don’t know either… On top of that, I am getting some odd results when using your script - with inserting a file named Node1 that contains a single sphere at the origin into a blank new file - when I run it for the first time here I get 2 objects created:
import rhinoscriptsyntax as rs rs.Command("-_Insert _File=_Yes _LinkMode=_Link Node1 _Block _Scale 1 _Rotate 90 0,0,0") objs=rs.LastCreatedObjects() print len(objs) for obj in objs: print rs.ObjectType(obj)
One type 8 (surface) and type 4096 (block instance)… ?? However, the file info says I only have one block instance. I assume it’s this way because the surface (sphere) has to also be in the file at least once somehow?
Also if I undo the script, then run it again, then undo a second time I get a funny error message (below). @stevebaer Can you explain any of this? I am always confused working with blocks and scripting methods, some of which work on block definitions and some of which work on block instances…
@Helvetosaur I’m getting similar, but not identical, results when running your script on your file.
The first time I run the script I get two objects: 8, 4096. If I undo the script and run it again it now has three objects instead of two: 2, 8, 4096. If I undo the scrip again and run it I also get the same error message you describe. Subsequent runnings of the script continue to produce 2, 8, 4096.
If I select and delete and then run the script again I get: 1, 4096.