How can I reference selected components inside GhPython?

Currently I am working on a script that can help me organize my workflow by using advantage of the scribble (load from rhino) functionality.

What I am currently trying to find out is how to access a list with all the components that exist inside a grasshopper definition, and from that point I would like to follow by filtering out those who are currently selected.

I currently work with python and don’t know much about C#, so if this is achievable through python, it would help me greatly to understand the definition.

I appreciate anyone taking time to help me out. And if more information is needed, just let me know!

If you set canvas = ghdoc.Component.Attributes.Owner.OnPingDocument() then there’s a canvas.AddObject method (which for example can be passsed a GhPython.Component.ZuiPythonComponent(), or other component class instance defined in your code).

The docs say there’s also a canvas.Objects property, and there even should be .SelectedObjects and .UnSelectedObjects methods. Otherwise do a print(dir(canvas)) and look through its attributes for what you need.

.

1 Like

Thanks for the reply!

I got them through…
Gh_Components = gh.Instances.ActiveCanvas.Document.Objects

Which seems to give the same output, but let me see if I can figure out what you said about “.SelectedObjects” and “.UnselectedObjects”.

I’ll update if I find a dead end :stuck_out_tongue: , but thanks for the help!

1 Like