I am trying to use blender to create a visualisation, and I have set up a 'template' object with geometry nodes that I can copy and manually manipulate to set the desired shape and colour. This works.
The GN input panel is with inputs is:
I am now trying to read a set of data from a CSV file and programmatically set up the visualisation elements. I can read the correct data from the file. I pass the data to a python routine, the relevant routine (ignoring the main code) is:
def createRFBandObject(name: str, lower: float, upper: float, power: float, category: int, showPower: bool):
print(f"{name} is ({lower}, {upper}, {power}, {category}, {showPower})")
obj = bpy.data.objects['RFBandTemplate'].copy()
obj.name = name
nodeGroup = obj.modifiers['RFBand'].node_group
nodeGroup.inputs['Lower (GHz)'] = lower / 1000 # Convert to GHz
nodeGroup.inputs[3] = upper / 1000 # Convert to GHz
#nodeGroup.inputs[4] = power
#nodeGroup.inputs[6] = category
#nodeGroup.inputs[5] = showPower
obj.data.update
return obj
For completeness:
Found Geometry Node modifier RFBand
Input Input_0 is named Geometry with type GEOMETRY
Input Input_7 is named UoM (MHz or GHz) with type STRING
Input Input_2 is named Lower (GHz) with type VALUE
Input Input_3 is named Upper (GHz) with type VALUE
Input Input_4 is named EIRP (dBW) with type VALUE
Input Input_5 is named Show power? with type BOOLEAN
Input Input_6 is named Category with type INT
The routine creates the right type of object but does not set the correct attributes (does not set any attributes at all). The above code as written will not run due to TypeError: bpy_prop_collection[key] = value: invalid, expected a StructRNA type or None, not a float
. My search of StackExchange and other sites suggest using .default_value
which is not logical in the first place and, while not creating an error, does not change the attributes of the shape.
(Edit: default_value
, on investigation, does exactly as it says - it changes the default value in the underlying GN definition - thus changing it for all shapes that are using that GN setup.)
I am completely lost. How can I use python to set the GN inputs on the new shape I have just created?
[For reasons, I will not be uploading a copy of the blend file, or the data set. I know the shapes work as intended when data is entered manually, I know the template shape is being copied and named correctly, and I know the data is being ingested correctly.]