Running commands through Grasshopper


I’m searching for a general example showing how to use ghpython and the rs.Command() method.

For example, how would you run the _move command with ghpython given 3 flat lists of inputs (objects, ‘from’ points & ‘to’ points)? Do you need to set up a loop? Or what is the syntax to iterate through the lists?

My ultimate goal is to run commands from 3rd party plugins.

I’m just getting started with Python scripting.



Hello again,

I’m still working through this problem.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc

a = rs.PointCoordinates(y) #intentionally have only 2 points referenced
b = rs.PointCoordinates(z) #intentionally have only 2 points referenced

alist = []
alist.append(str(a)) #creates a list of 'from' points to iterate over
blist = []
blist.append(str(b)) #creates a list of 'to' points to iterate over

#attempt to create a list of objects to iterate over in the _move command
picked = rs.GetObjects("Select polysurface to move",16,True,True,True)
pickedlist = []
X = len(pickedlist)

#this works, but moves all selected objects across the 'to' and 'from' translations
#this is expected as there is no list of objects to iterate over
for i in range(X):
    rs.Command('move '+ alist[i] +' '+ blist[i] +'')
#this is what I would like to work, adding in an iteration over the 'pickedlist'
for i in range(X):
    rs.Command('move '+ pickedlist[i] +' '+ alist[i] +' '+ blist[i] +'')

But it looks like this isn’t possible

Clearly I’m a newbie. I would really appreciate some help!



I’d script this differently.
Probably all the actions can be scripted with methods calls in the rhinoscriptsyntax module.
All user interaction can be done with the series of get methods.

So in your case you can call rs.MoveObject() rather than rs.Command('move')
For the vector you can call rs.GetPoint() to pick origin and destination, and construct by rs.VectorCreate()