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.
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.
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.
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.
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