2
$\begingroup$

I'm trying to link the values of a Named Attribute node to the scale vector of the Instance on Points node in Python but I couldnt find a way to do this anywhere...

I want to do something like this:

enter image description here

Here's my code as is:

def geo_node_func(node_group):
    
    #in and out group node
    inNode = node_group.nodes.new('NodeGroupInput')
    node_group.outputs.new('NodeSocketGeometry', 'Instances')
    outNode = node_group.nodes.new('NodeGroupOutput')
    node_group.inputs.new('NodeSocketGeometry', 'Points')

    #rest of the nodes
    mesh_cube_node = node_group.nodes.new(type="GeometryNodeMeshCube")
    instancepoints_node = node_group.nodes.new(type="GeometryNodeInstanceOnPoints")
    attribute_node = node_group.nodes.new(type="GeometryNodeInputNamedAttribute")
    node_group.nodes["Named Attribute"].inputs[0].default_value = "width"
    
    #instructions to link them
    node_group.links.new(inNode.outputs['Points'], instancepoints_node.inputs['Points'])
    node_group.links.new(mesh_cube_node.outputs['Mesh'], instancepoints_node.inputs['Instance'])
    node_group.links.new(attribute_node.outputs['Attribute'], instancepoints_node.inputs['Scale'])
    node_group.links.new(instancepoints_node.outputs['Instances'], outNode.inputs['Instances'])
$\endgroup$
0

1 Answer 1

3
$\begingroup$

This is a common problem caused by the fact some nodes have multiple inputs or outputs with the same name. It's not so confusing when they are visible simultaneously, but some nodes have modes, which switch which sockets are visible (and a user thinks a socket's type is changing, rather than which socket is visible). So the solution is to find the socket with the correct name and type:

output = next(o for o in attribute_node.outputs if o.name=='Attribute' and o.type=='VALUE')
node_group.links.new(output, instancepoints_node.inputs['Scale'])

To further clarify: you were creating a link successfully, but to a vector output, which was hidden, and a link to a hidden socket is hidden as well.

$\endgroup$

You must log in to answer this question.

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