I'm creating a script for data visualization and I want my data thats been loaded into an attribute to be selected for an input.

I like to write my blender code without using ops and context where possible.

How can I turn this input from a 'float' to this? enter image description here

I feel like this should be possible somewhere here


I tried setting the default value as the attribute but the default value only takes float. I can use the ops command in the console, but it's really ugly and I'd like to avoid that if possible.

bpy.ops.object.geometry_nodes_input_attribute_toggle(prop_path="[\"Input_3_use_attribute\"]", modifier_name="Geonodes")

Is this possible without ops?


1 Answer 1



First, get the modifier:

obj = context.object # or get the object in other way
gnmod = None
for gnmod in obj.modifiers:
    if gnmod.type == "NODES":

Then get identifier of socket. (Since "Input_3" is quite random number you have to get identifier from socket name) In my code, I create new one it if it doesn't exist, just in case:

inputs = gnmod.node_group.inputs
if "MyAttr" not in inputs:
    inputs.new("NodeSocketColor", "MyAttr")
id = inputs["MyAttr"].identifier

Then you can set use attribute and set it (Let's say you want to set vertex color "Col"):

gnmod[id+'_attribute_name'] = "Col"
gnmod[id+'_use_attribute'] = True
  • $\begingroup$ _use_attribute_name was what I was looking for. Awesome! thank you. $\endgroup$
    – TheJeran
    Feb 4, 2022 at 12:09
  • 1
    $\begingroup$ Incase anyone has the issue of the object not updating after changing modifier, you can use obj.data.update() $\endgroup$
    – cak3_lover
    Nov 19, 2022 at 20:37

You must log in to answer this question.

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