BrendanParmer / NodeToPython

Convert Blender node groups to a Python add-on
MIT License
236 stars 21 forks source link

Fix multiple default values #9

Closed BrendanParmer closed 2 years ago

BrendanParmer commented 2 years ago

Blender's input socket collections for some reason don't use unique keys for certain nodes, using input.name instead of input.identifier. For example, the Accumulate Field node input sockets look like

{
    "Value" : (1.0, 1.0, 1.0),
    "Value" : 1.0,
    "Value" : 1,
    "Group Index" : 0
}

when it should be

{
    "Value Vector" : (1.0, 1.0, 1.0),
    "Value Float" : 1.0,
    "Value Int" : 1,
    "Group Index" : 0,
}

In this case, we can get around it by accessing values using indices rather than the keys themselves, since we're just copying the original node.

#old
node.inputs["key"] = value

#new
node.inputs[key_index] = value

But this approach makes it more difficult to tell what value is actually being set here, at least without a comment saying the name.

I'll probably submit a bug report to Blender and see if it wouldn't be too bad to fix this issue.