Default values of ghpython inputs

Hi,

Is it possible to set the default values of a scripting component from inside the code in such a way that when hovering over the input the hint displays that default value?

Second question is related to the first one. Can I set the type?

NOTE: Assume that component will be compiled to .ghpy.

Thanks in advance.

There are docstrings, see point 1.4 of Tutorial: creating a Grasshopper component with the Python GHPY compiler.

The Grasshopper SDK also allows for directly setting the Description property of Inputs/Outputs, as noted by Mostapha here.

I know about the description, I meant about actual value/type.

I’m using your script for compiling do I need to connect containers (like Number) with some value in it while compiling?

Ah, the default content, OK.

That you can set with the ‘Advanced compilation mode/Copy compilable code’ option, after you copy the code and before you compile it manually. Inside the RegisterInputParam() call, you are allowed to set defaults via the https://developer.rhino3d.com/api/grasshopper/html/T_Grasshopper_Kernel_GH_Component_GH_InputParamManager.htm pManager instance that you are given.

If you need a sample, please copy your def RegisterInputParams(self, pManager): here.

Thanks,

Giulio


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

Thanks Giulio,

I guess I’m not gonna be able to simply use your compiling.gh scripts.

I’ll have to use something else using System.IO and acutally providing the .py files in order to automate all this.

For now, just save the files in a folder. When you have tons of files to update, it will be clear what type of meta-script will be needed.

If you need to edit the def RegisterInputParams(self, pManager): function (provide defaults, change some behavior, etc), you will need to edit your compiled code anyways before going to compile it. So it’s just better to use the folder with the .py files as source, edit it to your needs, and compile that. Do not use the evaluated component as base all the time. That is OK if you do not compile your code.

What do you mean by “evaluated component”?

image This?

I’m not using that, I’m compiling my own stuff.

Secondary question:
How can I change the output path?
There’s no method inside assemblySettings where I can set a path, instead of using assemblySettings.GenerateDefaultPath()

I mean the GhPython component on a Grasshopper canvas. I suggest to just use .py files as the source repository.

You set the file name in point 2.5 of the tutorial:

import clr

clr.CompileModules("Axes.p2.7.5.0.ghpy", "Axes.py", "Axes_helper.py")

after the local assembly is saved to disk, you can move the file to any location.
Again, those methods you are trying to use are simply used for the automatic one-click compilation, they are not meant for advanced customization.

That’s kind of it, I don’t want to have to move the file, I want it to be in my project folder ready to be zipped and shipped.

Can I make it a wish then? Why provide such a beautiful thing like compiling-sdk.gh then restrict it, not provide enough methods to make it more advanced?

All that modifying the code editing the py files, copy compilation code all this could be automated with just a few scripting components in GH. This way you can have a GH definition for each project containing the latest version of your components (assembly, plug-in, whatever).
The update/upgrade of your project will be a single click. Isn’t that we’re all after, “…making the world a better place…”? :wink:

3 posts were split to a new topic: Creating a default value for a GHPY compiled component