Python - Set Data Type of Inputs (Not Type Hint)

Hello,

How can I set the data type of inputs from within the python script?

I know I can wrap the python script in a cluster, and add nodes like “data” “boolean” etc in between the input and python input to then be able to “set” the inputs of the cluster, I would like to achieve this with the python component only.

Currently if I right click an input I can “set data item” but if this is a boolean for instance I want to see “set boolean” here instead.

Thanks for any help and leads!

Current:
image

Expectation:
image

This might help:

If you’re trying to create a component from scratch complete with custom control over UI elements, you’re not going to get that functionality from a single script component.

Thanks @AndersDeleuran I did come across your post in my findings earlier and perhaps I’m misunderstanding it or not phrasing my question correctly.

I am trying to achieve the following in a similar way to how ghenv.Component.Param.Input[0].Name = “Param Name Here” works

in the way that that specifies the name of the input i would like to specify the type as well, something like (making this up):

ghenv.Component.Param.Input[0].Type = Bool, False

where bool would set the input to type Boolean and the second value would set the default value to false.

this way when i drop the component on the canvas and right click the input i could set True or False as you can with native components.

Thanks for your help!

I see @jsb.walker , thank you. So I would need to go more the plugin development route then as the functionality is not available un a GH Python Script Component, am I understanding that corrrectly?

As far as I’ve come across, yes, you need to use development tools to explicitly type the input of a component.

Though what you’re describing would be a helpful feature. I’d probably add user controlled explicit typing to clusters over scripting components. It shouldn’t be too difficult to have cluster components inherit the typing of the first casting component that the inputs are attached to or something.

Good to know and I believe cluster inputs/outputs do inherit the type/info of what they connect to which is nice. My current workflow has been to wrap python components inside a cluster and connect a node of the type i want in between the cluster input and the script input. This allows me to have “pretty” looking custom components and allows me to right click and set the input based on data type.

i just was hoping to be able to specify this directly in the scripting component so that im not wasting overhead or adding complexity by wrapping a perfectly functional script in a cluster.

You’re right, I never noticed before but they do. I think that’s your easiest option for the functionality you’re looking for.

1 Like

Ah yes, I missed the setting of the data part, my bad. I think you need to fiddle with the parameter volatile data. This is for outputs, but have a look:

That said, when I need a default input value I just check if the parameter variable is None (for item data) and then set the variable to the default value within the script (i.e. before running any code as part of the input checks). And then document this in the parameter docstring so the user knows what’s going on.

Edit: Jesus, sorry again. I understand now. And yes I think a compiled component is probably the way to go. Though I suspect one could do it when running a GHPython component in SDK mode.

1 Like

:eyes: ooo interesting! I turned on the SDK mode it appears to give me a “behind the scenes” look at some of the things defining the component in general but wondering what to search for in the API docs regarding setting input types?

What syntax do you use to define an input type in a compiled plugin component?

I can’t find any information in the API docs about setting input types

Have a look at Giulio’s example here:

1 Like

Perfect thank you, I’ll do some reading!

1 Like