Import .ghuser component

grasshopper
(Eduszh) #1

Hello @piac ,

Thank you very much for your contribution to the Rhino software.

I have been using Grasshopper for a while now, and recently I have been trying to import GH plugins while writing my codes in Rhino Python Editor. I am wondering if it is possible to import .ghuser components (plugins) in Rhino Python Editor? All ladybug/honeybee plugins have that type of format so I am wondering if it is possible to import them directly in the script.

Also, I have some .ghpy custom components. However, I am not able to import them through import ghpythonlib.components as gh since these custom components are not found. So I am wondering if this is the right way to use it?

Thank you very much for your advice.

1 Like

(Giulio Piacentino) #2

Hi @eduszh

there are a series of unified questions, I’ll answer them one by one.

User objects are not plug-ins. They are a different concept in the Grasshopper SDK. Right now, they are not part of NodeInCode, and therefore, they are also not part of the items available with the ghpythonlib.components library.

All Ladybug components share a lot of data and functions with one another. They do so without the usage of NodeInCode: as they are open-source, you can see how they achieve that. It’s mostly simple classes that provide that overall advanced functionality!

You can get access to their data types even in the EditPythonScript editor, but you will need to pass that data in some way to it. For example, by filling the scriptcontext.sticky dictionary with their values. They are not part of NodeInCode because they are not a component, however.

This was an original question that had to be addressed. If .ghpy files are able to use all ghpythonlib.components, then all ghpythonlib.components need to be loaded in order to load .ghpy’s. Unless an additional mechanism is added that fetches only the names, then replaces the stubs lazily with the functionality, it’s one or the other. I needed to choose one for the first release, and I picked .ghpys to use NodeInCode. (Not NodeInCode to include ghpys). I just added report RH-52131 for this wish.

2 Likes

(Giulio Piacentino) #3

Sorry, I missed this part. The answer is, “Not really”. Ghpy’s are only meant to hide the source code when you do not wish to publish it. They do not really serve other purposes. They are usually a feature that is requested by some developers who make a living off niche/special consulting.

1 Like

How to load custom-written components by import ghpythonlib.components as gh
(Eduszh) #5

Hello @piac,

Wow, thank you very much for your time answering! Much appreciated!

Just to confirm: at this moment, if I want to run a plugin (especially Honeybee/Ladybug) as a function, the ONLY way to do it is through scriptcontext.sticky? Do you know if I can run a plugin iteratively with the use of scriptcontext.sticky? As far as I know, components on GH canvas only run once when I start the program or there is a manual change to the inputs. Therefore, I was thinking about wrapping the entire plugin in a function and store the function itself in sc.sticky. However, it does not always work (https://discourse.ladybug.tools/t/runtime-error-argumentexception-instance-property-item008-is-not-defined-for-type/5946/2) so I am thinking about alternatives that do not require me to have a significant modification to the plugin itself.

Thank you very much again!

Zhang

0 Likes

(Giulio Piacentino) #6

Hi @eduszh

it probably depends from the type of code that you are trying to run. If the plug-in installs some modules (some .py files), then you can import those modules. If all the code is in a component, then probably there will be some function that you could export. If so, you could pass that function as an output and evaluate it later. Same for custom classes or instances. I don’t know enough about Ladybug (it seems your questions relate to it) to be able to exactly specify what will be best and what will be possible. There will probably even be more ways…

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

0 Likes

(Giulio Piacentino) #7

For example, why not just leave Ladybug components be, and focus on setting their input/harvesting their outputs automatically?

0 Likes

(Eduszh) #8

Hello @piac,

Thank you very much for your response.

Yeah I think this is the best solution, but I am not sure how to achieve this to set the input/output in a automatic, iterative fashion.

Thank you for your time,

Shen

0 Likes

(Giulio Piacentino) #9

For example, Accessing GH canvas componens from Python (outside of GH)

0 Likes

(Eduszh) #10

Hello @piac,

Thank you very much.

I am very new to Rhino so I am not sure how to do this properly.
So I started a new post with my questions related to this approach. GH_Document object
Thank you very much for your help!

Shen

0 Likes

(Giulio Piacentino) #11

This post contains a pretty comprehensive sample:

0 Likes