I’m struggling to find the reference object through GUID.
My initial goal is to use rhino group as an input in grasshopper, and keep it separately in data structure.
I found useful to use plug-in fabtool
to obtain group-like data structure in grasshopper.
Now, the issus is I’m not able to get the object in grasshopper through GUID, somehow the rs.coercebrep only return None.
Anyone have an idea about this?
getObject.gh (93.0 KB)
getObject.3dm (14.4 MB)
Hello - I poked at this a little and I see that it does not work as is, but similar code in a straight python gets the breps. I’ll need to defer to the GH experts - I’ll shift this to the GH forum.
That should do it, however I’m not a reliable source I’m still learning.
ghObjects = ghenv.Component.OnPingDocument().Objects
myComponent = None
for obj in ghObjects:
if obj.InstanceGuid == "something something":
myComponent = obj
the similar code is still using “coerce” type of code?
Seems like still doesn’t work.
Are you expecting
would still remain the group-like data structure in grasshopper?
Of course it’s
None, you’re comparing the GUID with “Something somehing”, place your GUID there to search for.
I’m pretty sure @shaunwu25 is referring to GUIDs and objects referenced from the Rhino document, not GUIDs of objects on the Grasshopper canvas (to prevent further confusion). In which case, one should be able to use the coerce functions to get the RhinoCommon object from a GUID. There are several of these functions for the various geometry types etc. So you’ll likely have to do some checking and call the appropriate one. For some reason I can’t seem to get the
rhinoscriptsyntax search/documentation to play nice (there appears to be no
coerceFoo functions in there!), but perhaps trawl through here:
Edit: If you’re getting
None, perhaps you haven’t set the
scriptcontext.doc to the active Rhino document like so:
Oh, I get it now. Well it wasn’t very clear.
@AndersDeleuran thanks for the explanation and your support.
The truth is I wasn’t sure the GUID from fabtool is referencing Rhino or Grasshopper document.
Now is working perfectly.
I upload the code below in case anyone is interested.
You could probably negate fabtools entirely by digging a bit further into the available
rhinoscriptsyntax functions for this stuff. Here’s a basic example of getting the RhinoCommon geometry objects of guids referenced from the Rhino document, and then adding these to a
dictionary based on which groups they belong to, and finally shoving this into a
180906_GetGuidObjectsGroups_00.gh (3.3 KB)
180906_GetGuidObjectsGroups_00.3dm (672.6 KB)
That said, I personally recommend operating with layers for structuring interfaces between Rhino objects and Grasshopper, using the standard geometry pipeline, or through scripting where appropriate. I suspect you might run into some unforeseen kinks with things like un-grouping, re-grouping, nested groups, deleted groups and such.
@AndersDeleuran Thanks a lot! what a smart script!