Hello,
I am trying to port IronPython scripts to Rhino8/python3. We have a bunch of Components that append input params dynamically. I can now add the input params, but they do not collect any data. I can see by printing param.VolatileData
that they are registering a connection to a source, but I don’t know how to get the values from the sources. Below is my code, which I have in a python3 component with a button connected to the first input. Clicking the button causes the additional params to instantiate, but they do not seem to collect any data.
import Grasshopper
class MyComponent(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, *args):
if args[0]:
for name in ["arg_1", "arg_2", "arg_3"]:
add_gh_param(name, ghenv)
for param in ghenv.Component.Params:
print(param.VolatileData)
return [arg for arg in args]
def add_gh_param(name, ghenv):
params = [param.NickName for param in getattr(ghenv.Component.Params, "Input")]
if name not in params:
param = Grasshopper.Kernel.Parameters.Param_GenericObject()
param.NickName = name
param.Name = name
param.Description = name
param.Access = Grasshopper.Kernel.GH_ParamAccess.item
param.Optional = True
ghenv.Component.Params.RegisterInputParam(param)
print("number of input params", len(ghenv.Component.Params.Input))
ghenv.Component.Params.OnParametersChanged()
When I add more inputs via the ZUI buttons, I the code generated args then pass the data to the *args in RunScript(). I can see that ghenv.Component.Params.Input
contains the correct number of parameters, but the component seems to only read the number of inputs that are default with the component plus whatever is added manually with the ZUI.
I assume this is still a work in progress, but It would be great to know if there is some sort of workaround.
Thanks!!