Get cluster grand parent nickname for nested python component

Hi ,

I want to get the nickname for grand parent (parent of parent ) for nested ghpython component on GH .
( I found already c# component that can get parent only , which is attached here)

clusterdetection.gh (8.0 KB)

Thanks you in advance

Emad

Hi Emad. While you’re running a GhPython component in SDK mode, inside the RunScript method you have access to self, the component itself. Using that you can do:

doc = self.Attributes.Owner.OnPingDocument()
names = [GH_component.NickName for GH_component in doc.Objects]

If you know what type the grand parent is, you can test each GH_component, e.g. type(GH_component) is GhPython.Component.ZuiPythonComponent
(I can’t remember where all the other component classes are, but try Grasshopper.Components or Grasshopper.Kernel.Components). There’s useful information about how the components are connected in self.Params. Maybe another attribute has a link to the parent Cluster - I would just experiment using the intellisense autocomplete, and print(dir(self))

The API could be better documented, but there are some useful methods for Clusters:
https://developer.rhino3d.com/api/grasshopper/search.html?SearchText=Cluster

You can access the Grasshopper document server and get the second highest level document. This appears to work with arbitrarily deep nestings, but I haven’t tested it thoroughly:



230210_GetClusterNameDeepNestings_00.gh (5.8 KB)

2 Likes

@AndersDeleuran thanks for your respone .

I checked it but for some reason it is not working when you run the gh graph , it works just when you open python editor , but when you put in cluster and run the graph it is not

Afraid I don’t quite follow, if you can provide some demonstration of this behaviour that’d help tremendously. (preferably a video capture and the Grasshopper file).