Grasshopper

algorithmic modeling for Rhino

I want to execute a rhino command i.e. rs.Command(...) that requires some curves to be selected. How does one set some curves, inputs to the python script as selected objects?

Views: 2015

Replies to This Discussion

Hi Mark

you could change the target of the GhPython document:

import scriptcontext as sc
import Rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc

Then the selection methods will work:

import rhinoscriptsyntax as rs
rs.SelectObjects([x,y])

Here is an example... (draw two curves and make Grasshopper get them).

You can put back the Grasshopper document like this:

sc.doc = ghdoc

I hope this helps.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

Sorry I was not clear - I dont want to have operator involved in the selection. The command I need to execute will, in usual operation, prompt for selection. I want to set as selected the two curves I have generated in my grasshopper script before running the command. Goal is to have the command execute without any operator intervention. I am (reasonably) sure it is possible, but is beyond my current understanding of rhino SDK. 

thanks

Thank you for the response. It has (finally) become clear that geometry created in grasshopper can't be selected in Rhino until baked. I found both Elefront and Human which offer components to bake with an ID - which makes two step quite reasonable. Once GUID is in hand it seems possible to Find the object and then just set/clear using Select method. Among the (many) things I remain unclear about: if I reference a geometry (e.g. curve) into grasshopper and connect to my script I get something that looks like a guid. But clearly not "the" guid - but if I run through the ID component I get another string that does work (i.e. in rhinodoc.Objects.Find). I assume that the first is a grasshopper document specific version of the original - I have not found how i the ID component referencing  it back to the rhinodoc guid. 

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service