# Running Rhino commands in Grasshopper Python

**URL:** <https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380>\
**Category:** Scripting\
**Created:** [July 6, 2015, 12:23pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380 "2015-07-06T12:23:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shridhar\_Mamidalaa](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/shridhar_mamidalaa/32/145639_2.png) [@Shridhar\_Mamidalaa](https://discourse.mcneel.com/u/Shridhar_Mamidalaa)\
**Post date:** [July 6, 2015, 12:23pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/1 "2015-07-06T12:23:51Z")

</div>

Hello wizards,  
I have been using rhinoscriptsyntax for a while , now i wonder how commands from rhino can be [used.In](http://used.In) my case “mesh from points” i have seen a script long back trickily made it was “Reduce mesh” . plz do guide me On how its done .

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 6, 2015, 2:55pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/2 "2015-07-06T14:55:09Z")

</div>

Hi Shridhar

You can use `rs.Command(macro)` to execute a macro. A macro is the exact code that you would write in the command line to run a command.

Example: `rs.Command("_Line 0,0,0 2,2,2")`  
See the rhinoscriptsyntax help for more information (push F1 in the \_EditPythonScript editor).

I hope this helps,

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Shridhar\_Mamidalaa](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/shridhar_mamidalaa/32/145639_2.png) [@Shridhar\_Mamidalaa](https://discourse.mcneel.com/u/Shridhar_Mamidalaa)\
**Post date:** [July 6, 2015, 4:32pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/3 "2015-07-06T16:32:31Z")

</div>

Thank u Piac 😄 That helped but i couldn’t get it running on Grasshopper . I m guessing that points should be baked from gh to active document and get points from document … or is there any way ???

import rhinoscriptsyntax as rs  
import math  
a= rs.command("\_MeshfromPoints",True)

is something i ran on rhino py console… donno why py gh didnt work …

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 6, 2015, 4:50pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/4 "2015-07-06T16:50:15Z")

</div>

Oh you want that in Grasshopper. I just did a quick search and Tudor already wrote that script, maybe not in Python, but it should work as advertised. If you want to translate it to Python, it should also be possible.

> **[MeshFromPoints](http://www.grasshopper3d.com/forum/topics/meshfrompoints-1)**
>
> Hello everyone,
>  
> this is a small script which introduces the meshFromPoints command.
> Prior to using the script, make sure you've installed the MeshFromPoints…

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Shridhar\_Mamidalaa](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/shridhar_mamidalaa/32/145639_2.png) [@Shridhar\_Mamidalaa](https://discourse.mcneel.com/u/Shridhar_Mamidalaa)\
**Post date:** [July 6, 2015, 4:53pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/5 "2015-07-06T16:53:03Z")

</div>

Yes Piac… i have this component in gh but since i m a begginer i m trying to recreate basic to tricky components to teach myself Code.

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 16, 2015, 12:26pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/6 "2015-10-16T12:26:08Z")

</div>

Hi Giulio,

where can I look up, what Arguments the Command “\_Line” needs?  
Where Do I know that I need to attach “0,0,0 2,2,2” to that “\_Line”?

I ask that, because I need to know which argument “\_TextObject” command needs to generate a text solid with `rs.Command("_TextObject", True).`

Thanks a lot  
Regards  
Mr Sinter

---

<div class="post-metadata">

**Author:** ![603419608](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/603419608/32/487406_2.png) [@603419608](https://discourse.mcneel.com/u/603419608)\
**Post date:** [October 16, 2015, 1:02pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/7 "2015-10-16T13:02:01Z")

</div>

HI Mr\_Sinter

like this：

import rhinoscriptsyntax as rs  
str = rs.GetString(“get string”)  
rs.Command(" -TextObject " + str + " 0,0,0 “+” \_Enter")

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 16, 2015, 1:37pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/8 "2015-10-16T13:37:32Z")

</div>

Here is my generic sample for generating solids with a text object. There are a LOT of command line options and you do need to have them in the right order. --Mitch

```python
import rhinoscriptsyntax as rs

def CreateTextObjsAsSolids():
    text_string=rs.GetString("Text to insert?")
    if not text_string: return
    pt=rs.GetPoint("Text insert point?")
    if not pt: return
    ht=rs.GetReal("Text height?",minimum=0)
    if not ht: return
    thk=rs.GetReal("Solid thickness?",minimum=0)
    if not thk: return
    
    opts='_GroupOutput=_Yes _FontName="{}" _Italic=_No _Bold=_No '.format("Cambria")
    opts+='_Height={} _Output=_Solids _Thickness={} '.format(ht,thk)
    opts+='_LowerCaseAsSmallCaps=_No _AddSpacing=_No '
    
    rs.EnableRedraw(False)
    rs.Command('_-TextObject '+opts+'"'+text_string+'"'+' '+str(pt),True)
CreateTextObjsAsSolids()

```

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 16, 2015, 1:41pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/9 "2015-10-16T13:41:59Z")

</div>

That is absolutely great!

Thanks a lot  
Grz Mr\_Sinter

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 19, 2015, 8:38am UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/10 "2015-10-19T08:38:29Z")

</div>

Hi Mitch,

I don’t know where I can look up what arguments commands like “\_-TextObject” need…

How can I find out, that this command takes options such as those `"_GroupOutput=_Yes _FontName="{}" _Italic=_No _Bold=_No "`…?

I need this knowledge for several commands, as I want to start Grasshopper with some arguments too…

Thanks a lot in advance  
Mr Sinter

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [October 19, 2015, 12:39pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/11 "2015-10-19T12:39:26Z")

</div>

Hi @Mr_Sinter,

that is a macro. You can read about macros in the RhinoScript 101 PDF:  
[http://wiki.mcneel.com/developer/rhinoscript101](http://wiki.mcneel.com/developer/rhinoscript101)  
These are just the options that end up being written in the command line when you run a command. The hyphen sign (or minus) “-” is used to trigger the no-dialog version of the command. Please read more in the Rhino Help, under macro, or in the PDF above.

I hope this helps,

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 19, 2015, 12:58pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/12 "2015-10-19T12:58:44Z")

</div>

Hi @piac,

I read about macros in “[http://wiki.mcneel.com/rhino/basicmacros](http://wiki.mcneel.com/rhino/basicmacros)”, but it also did not tell me where I can look up which arguments a macro needs/accepts.  
Like I asked, how can I see in advance that the macro `_TextObject` has `_Bold=_No` as argument?

I tried it with this method:

```
command_id = rhi.Commands.Command.LookupCommandId('_GrasshopperOpen', False)
print "%s"%rhi.Commands.Command.DisplayHelp(command_id)

```

But this did not gave me a list of which arguments the macro `'_GrasshopperOpen'` accepts…  
I need to open a certain GH-file with `'_GrasshopperOpen'` and additionally perform a Grasshopper Bake on a Rhino geometry…

Thanks much in advance  
Mr Sinter

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [October 19, 2015, 1:12pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/13 "2015-10-19T13:12:56Z")

</div>

You can see that by running the Rhino Command.  
Type “\_-TextObject” in the Rhino command line. You will see…

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 19, 2015, 1:33pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/14 "2015-10-19T13:33:47Z")

</div>

Type in “\_-GrasshopperOpen” in the command line, you’ll see what I mean…  
This does **NOT** give me the list of arguments this macro accepts, there appears another command line which says:  
"  
**`GH or GHX file to open:`**  
"  
I want to automatically start a certain GH-file with Grasshopper without being asked by Rhino…  
Additionally I want to see, if this `"_-GrasshopperOpen"`-macro accepts additional arguments, as I need to perform operations with GH on a brep with has been created in Rhino, and I want to “hand over” this brep automatically to GH

Thanks in advance

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [October 19, 2015, 1:45pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/15 "2015-10-19T13:45:33Z")

</div>

You inquired about “TextObject”. This request about \_GrasshopperOpen would make a good start of a new discussion.

Trying to automate Grasshopper from within a Grasshopper solution, while possible, opens several levels of issues. Be sure that you really know why you need this. The “\_GrasshopperOpen” command simply accepts an argument without an option. This means that you are forced to put that one option there, and there are no additional options to call after that.

It’s possible in other cases that a developer intentionally adds hidden commands or command options. It is not possible to know which ones exist, or how to invoke them, unless the developer reveals them. In this case, there are no command options to call (that I know of).

Please start a new discussion if you need help regarding a specific command macro.

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 19, 2015, 1:54pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/16 "2015-10-19T13:54:37Z")

</div>

Alright I see…The only way to see what arguments these macros accept is to try it out in the command line…

So I found out in try-and-error-style how to open a specific GH-file by script:

```
rs.Command('_-Grasshopper' +' '+ 'Document' +' '+ 'Open' +' '+ 'somefile.gh')

```

This still does not resolve for me the question why there is a scripting docu about Rhino and rhinoscriptsyntax, but none about macros…

Nevertheless thanks very much so far  
Regards,  
Mr Sinter

---

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/759176_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [October 19, 2015, 5:43pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/17 "2015-10-19T17:43:00Z")

</div>

@Mr_Sinter,

check out the example below, with the attached DrillHole.gh file. Basically the script does the following:

- Select a solid brep (eg, a sphere or box)
- Get the Grasshopper plugin object
- Open the DrillHole.gh file
- Pass the id of the brep to an existing slot in gh file
- Change any parameter in the gh file
- Run the Grasshopper solver
- Bake the resulting brep to rhino and select it

```auto
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DrillHoleWithGrasshopper():
    id = rs.GetObject("Select a closed brep", 16, True, False)
    if not id: return False
    
    Grasshopper = Rhino.RhinoApp.GetPlugInObject("Grasshopper")
    if not Grasshopper: return False
    
    Grasshopper.OpenDocument("C:\DrillHole.gh")
    Grasshopper.DisableSolver()
    Grasshopper.AssignDataToParameter("input_brep", id)
    Grasshopper.AssignDataToParameter("circle_radius", 2.0)
    Grasshopper.RunSolver(True)
    
    objs = Grasshopper.BakeDataInObject("output_brep")
    if not objs: return False 
    rs.SelectObjects(objs)
    
    Grasshopper.CloseDocument()
    Grasshopper.HideEditor()
    
if __name__ ==" __main__":
    DrillHoleWithGrasshopper()

```

Do not forget to change the file path in the script above which loads the DrillHole.gh file into Grasshopper.

[DrillHole.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/8/c/8c702a480291f2177bfa0fdd40a01b73d8233a96.gh) (8.4 KB)

- 

c.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [October 19, 2015, 5:44pm UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/18 "2015-10-19T17:44:07Z")

</div>

> [@Mr\_Sinter](#):
>
> This still does not resolve for me the question why there is a scripting docu about Rhino and rhinoscriptsyntax, but none about macros…

Well, you might imagine there are close to 1000 Rhino commands. That would require writing a ~1000 page documentation… Best is just to run the command with a dash and look at the arguments. --Mitch

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 20, 2015, 9:28am UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/19 "2015-10-20T09:28:43Z")

</div>

Hi Clement,

regardless of these Grasshopper operations working correctly (for me they do not…no holes are punched in the solid), your post is really great. This is exact the “data handover” from rhino to grasshopper I need!  
I will apply your example to my specific application case

Thanks a lot  
Mr Sinter

---

<div class="post-metadata">

**Author:** ![Mr\_Sinter](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mr_sinter/32/24474_2.png) [@Mr\_Sinter](https://discourse.mcneel.com/u/Mr_Sinter)\
**Post date:** [October 20, 2015, 9:30am UTC](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/20 "2015-10-20T09:30:03Z")

</div>

Yeah right, was just wondering…  
Maybe this issue will be solved by one individual who has lots of time

[Next page](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380.md?page=2)
