Call GH component created with Python GHPY Compiler from GH Python Script

Dear community, I created grasshopper component by following the steps that is represented at Tutorial: creating a Grasshopper component with the Python GHPY compiler . As understood, I came up with Grasshopper Python script and I converted it into a Grasshopper component by utilising Python GHPY Compiler. The question is, I aim to call that component within another Grasshopper Python script. But I am not able to manage it. Thanks in advance for answers.

Hi Arif,

I think it will require a lot of trial and error with compiled components,

I handled this using uncompiled launcher components (UserObjects) that all import the same Python package (containing the same MyComponent class for all of them; this can make your plug-in automatically update user’s definition’s too, if the launcher code doesn’t change) and the Command Pattern. Different commands are run depending onthe component’s name. IT’s trivial to call another component’s command, as it’s imported anyway in the caller’s own package.

To call a GH component directly, I haven’t found a way of accessing the unplaced components from all the user’s installed plug-ins on the ribbon. If the user has placed the component on the canvas that you want to call, it can be searched in an SDK mode component, for example to search for other GhPython components:

GH_DOC = self.Attributes.Owner.OnPingDocument()
[comp for comp in GH_DOC.objects if isinstance(comp, GhPython.Component.ZuiPythonComponent]

Outside of sdk mode I think you can use use attributes of ghenv.Component instead but I’ve not tried it.

Greetings James,

Thanks for reply. But, I think this is beyond the knowledge that I carry currently. I thought that there is a practical method to reach out to the components that are already compiled with Python GHPY Compiler.

You’re welcome Arif. It’s beyond my experience, but I have another suggestion:

I’m not sure, but I think that compilation method is a standard way of producing a .Net Assembly using clr. It’s a .Net thing possible due to Iron Python, not anything special about Grasshopper or Rhino. If you know where the .ghpy file is (in one of the Grasshopper.Folders… if it’s installed) then try adding its location using clr.AddReferenceToFileAndPath, and loading it like any other .Net Assembly with:

clr.AddReference(…)

https://ironpython.net/documentation/dotnet/

Maybe you have to make a copy of the file ending in .dll

If RunScript or the entry point is an instance method, I’d expect to have to find the MyComponent class in the Assembly and instantiate it, then call RunScript on that.