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.
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
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.
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.
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!
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…
for Robert McNeel & Associates
For example, why not just leave Ladybug components be, and focus on setting their input/harvesting their outputs automatically?
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,
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!
This post contains a pretty comprehensive sample: