Hello
How to get the group parent name (if available) or guid of the component?
I don’t quite follow, but these are probably the types/methods you’ll need:
240115_GetGroupObjectsGuids_00.gh (4.6 KB)
Thanks @AndersDeleuran
I need to find the group parent of the component if already there is a way , if not i will use the method you mentioned and compare guids
Ah right, so the other way around. You can edit the code a bit and that should do it (using NickName
here):
240115_GetGroupObjectsGuids_01.gh (4.6 KB)
1 Like
Thank you @AndersDeleuran
import Grasshopper as gh
objs = gh.Instances.ActiveCanvas.Document.Objects;
guids =[]
for obj in objs:
guids.append(obj.InstanceGuid)
if obj.Name == "Group":
for o in obj.Objects():
for id in guids:
if o.InstanceGuid == id:
print "Object:", o.InstanceGuid, "Parent Group:", obj.InstanceGuid
1 Like
No worries… quick warning: It’s probably best to avoid using id
as a variable name, as it is a built-in function:
1 Like
Thanks for the advice.
This is a test , i will convert the code to c#
import Grasshopper as gh
# Get all objects on the active canvas
objs = gh.Instances.ActiveCanvas.Document.Objects
# Dictionary to store parent group GUIDs and associated objects
parent_groups = {}
# Iterate through all objects
for obj in objs:
# Check if the object is a group
if obj.Name == "Group":
# Create a list to store objects in the group
group_objects = []
# Iterate through objects in the group
for o in obj.Objects():
# Add the object to the list
group_objects.append({'ObjectGUID': o.InstanceGuid, 'ObjectName': o.Name})
# Store the parent group GUID and objects list in the dictionary
parent_groups[obj.InstanceGuid] = {'GroupName': obj.Name, 'Objects': group_objects}
# Print each group along with its objects
for group_guid, data in parent_groups.items():
print"Group Name:", data['GroupName']
print"Group GUID:", group_guid
# Print information for each object in the group
for obj_info in data['Objects']:
print" Object Name:", obj_info['ObjectName']
print" Object GUID:", obj_info['ObjectGUID']
1 Like