Programmatically instantiated component / parameter behaves differently

A was created via python script, B manually.

It seems like s.th. about the 3rd parameter is different, as I have not seen this behavior with just the two default input parameters.

Looking at the .ghx file there is no discernible difference (other than different labels and Guids) though.

The parameter is created with this code:

 def addInputParam(node):
	nextIdx = len(node.Params.Input)
	name = string.ascii_uppercase[nextIdx]
	p = node.CreateParameter(gh.Kernel.GH_ParameterSide.Input, nextIdx)
	node.Params.RegisterInputParam(p)

	p.Name = name
	p.NickName = name
	p.Access = node.Params.Input[nextIdx - 1].Access
	p.Optional = True

	node.Params.OnParametersChanged()

I’m a bit at a loss here, so any clue is appreciated. Thanks a lot in advance!

weird.ghx (35.5 KB)

What actually is .Access? item, tree or list or what?

Yes. – See IGH_Param.Access Property

I guess, the question is: What does clicking “Insert Parameter“ do that my code isn’t doing?

I’ve only created GHPython components from code.

Before creating new params, I called ParamsSyncObj = Params.EmitSyncObject() (I don’t remember why).

To create Params on the components, I didn;'t use .CreateParameter, I instantiated Param_ScriptVariable directly (or one of the Param_Arc, …, Param_Number, Param_ScriptVariable, Param_GenericObject from Grasshopper.Kernel.Parameters).

I set param.TypeHint too, e.g. to GhPython.Component.GhDocGuidHint()

Then I called .RegisterInputParam with that object, and .OnParametersChanged(). I remember not making any changes with the component active - I only set

After adding all params, I called Params.Sync(ParamsSyncObj) and Params.RepairParamAssociations(). Again I don’t remember exactly why, but whatever I used in the end worked OK for me.

Thanks James,

I just tried different combinations of this:

syncObj = node.Params.EmitSyncObject()
p = ghk.Parameters.Param_GenericObject()
p.CopyFrom(node.Params.Input[0])
node.Params.RegisterInputParam(p)
node.Params.RepairParamAssociations()
node.Params.RepairProxyParams(doc)
node.Params.OnParametersChanged()
node.Params.Sync(syncObj)

Unfortunately I’m still getting <null>s.
However, when I save the file and reopen it, they’re gone.

So maybe the parameter itself is fine, but something about the execution of the entire graph is off?
I’m calling doc.NewSolution(expireAllObjects=True) at the end of the script though…

Not sure why, but running this after adding the parameter seems to make it work:

writer = GH_IO.Serialization.GH_LooseChunk('temp')
node.Write(writer)
node.Read(writer)
1 Like