I have written some custom script components using the new Python 3 component. In the instructions it is shown that such components can be published directly or with contextual inputs connected to it.
I cannot use the contextual inputs as i need a domain input which is not possible with the selection of contextual inputs. Further i would prefer all my components to be contained within one Grasshopper definition for easier development. Therefore I am not using them.
Publishing the plugin works fine and i can use the components. However the components do not execute without all inputs populated. How do I change this? Will there be a parameter manager for the python modules?
Switch the component into .sdk mode. Maybe in a Python 3 component you can then just use **kwargs, or even set defaults.
Otherwise, I know this works in Iron Python components: replace the first optional arg and all subsequent ones with *args, and then zip those together with the arg names from self.Params (or somewhere in the API to filter for ihe Input ones).
Any missing args are simply set to None by Grasshopper - your code within RunScript needs to work with this.
I am afraid, I do not understand. In this simple script how would you implement the *args without it being interpreted as (invalid) parameter name?
import System
import Rhino
import Grasshopper
import rhinoscriptsyntax as rs
class MyComponent(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, x, y, z):
if x:
a = x
if a and y:
a = a + y
if a and z:
a = a + z
return a
Thank you for the help, but I run into the same issue where *args becomes the value name. I tested it with both the IronPython and the Python3 component. Also it fails as the GH_ScriptInstance object has no object Params.
I am also having an issue with this, only when the components are published using the Unified Script Editor. I can get the input parameter to behave as an optional parameter (in the gh definition in which it is scripted) by using ghenv.Component.Params.Input[1].Optional = True but once it is published, it does not allow the component to run. Or I should say it does but frustratingly, not consistently. It seems to work in some of my custom python components and not in others and I cannot identify the difference.
Also probably a clue, if an input is connected and then unconnected, it then is fine with the optional parameter, which makes me think that the problem is trying to get the code to run once to set the optional parameter. ???
Okay I made adjustments and improvements to how .Optional property of input parameters is carried to published components. This is gonna be in Rhino 8.14:
Published Script Components
When publishing a Script component, all inputs are now following the Optional state of the original source script component input. The script inputs have been and continue to be marked as Optional by default:
Plugins published before Rhino 8.14, will continue to show the warning on the components to keep the existing behaviour. New plugins will carry the .Optional settings as described above.
Published Contextual Components
When publishing a full Grasshopper definition with contextual inputs as a component, the published component inputs are only marked as optional, if the corresponding contextual input has sources connected to it. No changes here.