# Get objects from a grasshopper component?

**URL:** <https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677>\
**Category:** Scripting\
**Tags:** python\
**Created:** [March 21, 2019, 2:13pm UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677 "2019-03-21T14:13:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![siemen](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/siemen/32/490472_2.png) [@siemen](https://discourse.mcneel.com/u/siemen)\
**Post date:** [March 21, 2019, 2:13pm UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677/1 "2019-03-21T14:13:43Z")

</div>

So I’ve been working on a python script that sets geometry into a grasshopper component using @clement 's great example here:  
[https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/17?u=siemen](https://discourse.mcneel.com/t/running-rhino-commands-in-grasshopper-python/22380/17?u=siemen)

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: [https://developer.rhino3d.com/wip/api/grasshopper/html/T\_Grasshopper\_Plugin\_GH\_RhinoScriptInterface.htm](https://developer.rhino3d.com/wip/api/grasshopper/html/T_Grasshopper_Plugin_GH_RhinoScriptInterface.htm)  
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?

---

<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:** [March 21, 2019, 3:35pm UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677/2 "2019-03-21T15:35:34Z")

</div>

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:

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

```

\_  
c.

---

<div class="post-metadata">

**Author:** ![siemen](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/siemen/32/490472_2.png) [@siemen](https://discourse.mcneel.com/u/siemen)\
**Post date:** [March 21, 2019, 3:55pm UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677/3 "2019-03-21T15:55:46Z")

</div>

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

---

<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:** [March 21, 2019, 4:04pm UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677/4 "2019-03-21T16:04:23Z")

</div>

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

 ![grafik](https://global.discourse-cdn.com/mcneel/original/3X/4/5/45989acbb2619112c1a8abdaa434481b9b7668c7.png)

\_  
c.

---

<div class="post-metadata">

**Author:** ![siemen](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/siemen/32/490472_2.png) [@siemen](https://discourse.mcneel.com/u/siemen)\
**Post date:** [March 22, 2019, 7:04am UTC](https://discourse.mcneel.com/t/get-objects-from-a-grasshopper-component/80677/5 "2019-03-22T07:04:17Z")

</div>

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 😉 .
