Arguments in rhinoscriptsyntax.Command

I’d like to create a TextObject programmatically - however, there’s no rhinopython command to create a TextObject.

I can use rhinoscriptsyntax.Command(‘TextObject’), but that throws me into an interactive situation where I type the text and set the insertion point.

Is there a way to provide the text and insertion point as arguments to the Command / TextObject function?

Use the “dash” version of the command - as in _-TextObject. Run the command with a dash first in Rhino to see all the command line options, then use those (copy/paste from command history) in your script to help create your command string for rs.Command().

Edit: for the insertion point in the command string you will need to convert a 3d point into a string. With Python you can actually just use str(pt) where pt is the 3d point

–Mitch

It’s actually somewhat complicated to set up, so below is an example… The extra quote marks around the text string is to accommodate text with spaces in it - otherwise you will only get the first word. The order in which you pass the command line arguments is critical.

import rhinoscriptsyntax as rs

text_string=rs.GetString("Text to insert?")
pt=rs.GetPoint("Text insert point?")
ht=rs.GetReal("Text height?")

opts="GroupOutput=No FontName=Arial Italic=No Bold=No Height="+ str(ht)
opts+=" Output=Curves AllowOpenCurves=No LowerCaseAsSmallCaps=No AddSpacing=No "

rs.Command("_-TextObject " + opts + '"'+text_string+'"' + " " + str(pt) )
1 Like

Thanks Mitch, this was extremely helpful! However, I’m still having some trouble getting this implemented.

When I try to run your example code (replacing GetPoint, GetReal arguments with real values), Rhino seems to get confused when it comes to unnamed arguments - I get an interactive dialog where RunPythonScript is asking me to provide a value for “Text to insert?” -

PS Is there a Rhino reference online where I can look at the arguments for different functions? The OSX version doesn’t show arguments like Windows does.

Can you post a sample of the code you’re running to test?

You mean the python rhinoscriptsyntax help? You need to look at this thread to set up the Dash docset so you can access the Help on Mac.

–Mitch

Sure. It’s basically the same code that you provided.

import rhinoscriptsyntax as rs

text_string=rs.GetString(“nnnn”)
ht=rs.GetReal(“12”)
pt=rs.GetPoint("[0,0,0]")

opts=“GroupOutput=No FontName=Arial Italic=No Bold=No Height=”+ str(ht)
opts+=" Output=Curves AllowOpenCurves=No LowerCaseAsSmallCaps=No AddSpacing=No"

rs.Command("_-TextObject " + opts + ‘"’+text_string+’"’ + " " + str(pt) )

Currently, the getString, getPoint, and getReal functions are acting interactive, even though I’m providing a value (they all prompt for a value.) Regardless of whether I input a value in the interactive box or not, none of the values get passed. No point gets chosen, the height is always the same, and the text is whatever I used for the last TextObject call.

Ahh, you can’t really do that. You would of course need the Help to see what each of these methods wants for arguments and in what order.

If you want to bypass the user input and specify a text, a height and an insert point directly, you don’t use these methods, you set them directly something like this:

import rhinoscriptsyntax as rs

text_string="nnnn"
ht=12.0
pt=rs.coerce3dpoint([0,0,0])

#etc.

HTH, --Mitch

Thanks but I am still not able to get this to work.

Current code:

import rhinoscriptsyntax as rs

text_string='test'
ht=300.0
pt=rs.coerce3dpoint([0,0,0])

opts="GroupOutput=No FontName=Arial Italic=No Bold=No Height="+ str(ht)
opts+=" Output=Curves AllowOpenCurves=No LowerCaseAsSmallCaps=No AddSpacing=No "

rs.Command("_-TextObject %s \"%s\" %s" % (opts, text_string, str(pt)))

I get a string of failures when I try to run this (on Mac):

Unknown command: GroupOutput=No
Unknown command: FontName=Arial
Unknown command: Italic=No
Unknown command: Bold=No
Unknown command: Height=300.0
Unknown command: Output=Curves
Unknown command: AllowOpenCurves=No
Unknown command: LowerCaseAsSmallCaps=No
Unknown command: AddSpacing=No
Unknown command: "test"

Unfortunately, this is normal - it simply looks like the dash version of -TextObject has not been fully implemented in Mac Rhino - there are no command line options other than the insertion point as there are in Windows Rhino. All other parameters are taken from those which are last set when you run TextObject (without the dash). In Windows Rhino your script runs.

Sorry, I didn’t realize that this had not been done, it’s only recently that we have had a TextObject command that works at all on Mac… There is a bugtrack item for this:

http://mcneel.myjetbrains.com/youtrack/issue/MR-1062

Guess you’ll have to wait a bit more for this to be fixed… :frowning:

–Mitch

Hi Mitch,

Similar situaton. I use Command(“meshIntersect"), which ask for picking up intersection meshes in the Rhino5 viewport. And I tried to use "-meshIntersect” to see all the command line options, however in Rhino5, there is no command line options displayed for it.

so… how can I do for passing intersection mesh to python instead of picking them in Rhino5?

much thanks!
Lei

That’s because there are no options for this command…

I am not sure what you need here - you are looking for the rhinoscriptsyntax equivalent of MeshIntersect? There is rs.MeshMeshIntersection() which returns the intersection of two mesh objects. Otherwise you can script rs.Command(_MeshIntersect)

–Mitch

Hi Mitch,

What Im trying to do is instead of picking meshes in Rhino5, I want rs.Command(“_meshIntersect(meshFromInputParametricModels)”). So I dont have to pick up mesh in Rhion5 and always stay in GH.

Thanks,
Lei

or give arguments to rs,Command("_meshIntersect(arguments)")

So this is a Grasshopper question? Grashopper has a Mesh/Mesh intersection component which you can use with Grasshopper geometry. As far as programming Rhino native commands inside a Python component in Grasshopper, I don’t really know how to do that correctly - maybe post that question in the Grasshopper section of the forum.

ahh yeah… I use Python in GH as a rookie.
Recently found rs.Command() function and thought it is so powerful.
so…the question is more about how far the rs.Command() could do even I understand we could do the function by MeshMeshIntersection. you know, just want tweak it bit more:P

Thanks so much for your help as always.
And I was wondering if there is a more detailed introduction about rs.Command(), which, at least I think, could discuss about how and what kind of commands in Rhino5 could take arguments inside rs.command(“commands”).

Best,
Lei

I would highly advise against going down this path (i.e. scripting macros), and instead start out with the rhinoscriptsyntax Python module or jump directly to the RhinoCommon API. For your case have a look at these methods:

https://developer.rhino3d.com/api/RhinoScriptSyntax/#mesh-MeshMeshIntersection

https://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_Intersect_Intersection_MeshMeshAccurate.htm

https://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_Intersect_Intersection_MeshMeshFast.htm

But before doing any of that, make sure to go through the GHPython basics here (else you’re gonna have a bad tiiime):

Cool!
thanks so much Anders:)

1 Like