Get objects from a grasshopper component?

So I’ve been working on a python script that sets geometry into a grasshopper component using @clement 's great example here:

Now I’m wondering: is there a way to retrieve objects from grasshopper as well by using a python script? So let’s say I set the objects to a geometry component in grasshopper. How can I retrieve afterwards which objects have been linked to that component?
I tried looking here but couldn’t find something which does what I need:
There’s a method to bake geometry from a component, but then I’d create objects on top of the objects I already have in Rhino (I think?). I just need the original linked objects.
Anybody a clue or example?

Hi @siemen, by importing Grasshopper namespace into python, you can access this. I’ll asume you know how to find document and components already. Once you have the GH component object, you might access the persistent data of it.

e.g. if you have a Brep component which has some breps assigned by the user, you can get Rhino object ids like this:

if component_obj.PersistentDataCount > 0:
    for data in component_obj.PersistentData: 
        if hasattr(data, "ReferenceID"):
            print "ObjectID:", data.ReferenceID


1 Like

Amazing @clement , this works perfect! So now how did you find this? What is this black magic you’re dealing with?

Hi @siemen, when you get the component_obj, add a breakpoint and run it, then you’ll see this:


Thanks! I understand there’s a lot of information to be found using those breakpoints. Just need to get to understanding how to interpret it and use it. I think at some point my head will make the click, until then I probably might still ask you a few times :wink: .