Set persistent data in a component's input parameter

I’ve written some Python to instantiate a component on the canvas, and would like to then set values to its input parameters. In this example, I created a Cull Index component and I want to set the Indices input to the value 3 and the Wrap input to False.

I used SetPersistentData() and it seems to work on the Indices input but not on the Wrap input. Instead of just a single False value, it appends False to the data list (first image).

The value I set for Indices also doesn’t seem to appear in its tooltip but instead says it is an empty parameter (second image).

How should I go about setting these inputs properly?

set_inputs.gh (2.7 KB)

Hey there,

You could use:
comp.Params.Input[1].VolatileData.Append(gh.Kernel.Types.GH_Integer(3))

Or perhaps make it a function if you use it more often, something in the lines of:

def add_input(index, gh_type, value):
    comp.Params.Input[index].SetPersistentData(gh_type(value))
    comp.Params.Input[index].VolatileData.Append(gh_type(value))

I also can’t seem to find any suitable solution, it actually seems to happen with all pre-defined values. Per default the structure seems to be populated. See below the same occurring with Insert List

Prior to SetPersistentData() the component already has “structure{1}” set (in this case the True value). However ClearData() i.e. doesn’t affect it. Deleting only index[0] of the PersistentData also doesn’t seem to work.

Same applies in another situation with i.e. a WeaveComponent

Curious as to what the answer will be if someone else comes by to eleborate.