10
$\begingroup$

Is there any way to get the input value and type of Geometry Nodes modifier I want to use these values in an addon, but these are not consistent, so I can't call it by using this command as sometimes it can be Input_3 despite its second input only

bpy.ops.object.geometry_nodes_input_attribute_toggle(prop_path="[\"Input_2_use_attribute\"]", modifier_name="GeometryNodes")

and I can't feed the values using this -

bpy.data.objects["Cube"].modifiers["GeometryNodes"]["Input_2_attribute_name"] = "UVMap"

as this will only work if the inputs are toggled to attribute only.

so is there any way to get the status of the input? and can we get all the inputs of a modifier and the input name and use Input name to make sure, we are feeding values for the right input, Like in the below example image second input's name is UVMap and I want to feed some value to the input of the modifier which has this particular name only and not by the name like Input_2

or is there any other better way of handling this situation?

Screenshot of the geometry nodes modifier

Edit:

I have some doubts, like we need to use this command to toggle to attribute mode, and is there any other way of toggling? or is it the only way? bpy.ops.object.geometry_nodes_input_attribute_toggle(prop_path="[\"Input_2_use_attribute\"]", modifier_name="GeometryNodes") as this method use "Inputs_2_use attribute" as string and we can't assign this value to variable and use it dynamically.

$\endgroup$
1
  • $\begingroup$ FWIW the operator can be overriden with the object key if you don't want to use the context : bpy.ops.object.geometry_nodes_input_attribute_toggle({"object": bpy.data.objects["Cube"]}, prop_path="[\"Input_2_use_attribute\"]", modifier_name="my_mod_name") $\endgroup$
    – Gorgious
    Feb 13, 2022 at 20:30

1 Answer 1

8
+50
$\begingroup$

Be aware that there is current a bug in Geometry Nodes and the assignment will not always work correctly.

That said, the way to get to the individual input fields is to go through the object's Geometry Node Modifier's node_group to get the relationship between the display name of the input field and the numeric position of the input field. Here's an example that assumes that modifier has already been set to the object's Geometry Nodes Modifier:

for input in modifier.node_group.inputs:
    print(f"Input {input.identifier} is named {input.name}")

Thus, if you know the name, you would search node_group.inputs for that name. That input would be the one you wanted.

Also note that the modifier's own name "GeometryNodes" can change and that an object can have more than one GeometryNodes modifier. Here's code that finds all of the GeometryNode modifiers of the active object and selects the first one in the list:

object = bpy.context.active_object

modifiers = []
for modifier in object.modifiers:
    if modifier.type == 'NODES':
        modifiers.append(modifier)
        print(f"Found Geometry Node modifier {modifier.name}")

modifier = modifiers[0]
$\endgroup$
2
  • 1
    $\begingroup$ Hi, thanks for your answer, and it helped me pretty much, but still I have some doubts, like we need to use this command to toggle to attribute mode, and is there any other way of toggling? or is it the only way? bpy.ops.object.geometry_nodes_input_attribute_toggle(prop_path="[\"Input_2_use_attribute\"]", modifier_name="GeometryNodes") as this method use "Inputs_2_use attribute" as string and we can assign this value to variable and use it dynamically. I hope you understood though this may be a little bit of unclear explanation $\endgroup$ Dec 20, 2021 at 17:48
  • 1
    $\begingroup$ We do have to use the toggle and as far as I know there is no other way. $\endgroup$ Dec 28, 2021 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .