0
$\begingroup$

I'm trying to access the keys of a particular node of inputs and outputs. to access the use property keys:

n = my_node #(From node_tree.nodes)

for key in n.bl_rna.properties.keys():
    attributes = getattr(n, key)

now I would like to access the attributes of n.inputs and n.outputs

but this does not produce any results:

for key in n.outputs.bl_rna.properties.keys():
    attributes = getattr(n.outputs, key)

I'm pretty confused about this, I'm probably wrong

Edit: For more details, this would serve to copy the nodes and their properties. But when I have to access the inputs and outputs properties I have difficulties at the moment, post a small test that I am running, for now it does not work properly, but perhaps it makes better understand what I am trying to do

for n in bpy.context.scene.node_tree.nodes:
    tipo_di_nodo = n.bl_rna.identifier ##Ty @batFINGER
    nodo_copiato = bpy.context.scene.node_tree.nodes.new(tipo_di_nodo)

    #This copies the node exactly, with some data         
    for key in n.bl_rna.properties.keys():
        source_attribute = getattr(n, key)
        if not n.is_property_readonly(key):
            setattr(nodo_copiato, key, source_attribute)

    #I would like it to copy and assign value inputs
    #For now this is not working
    for val in n.inputs.values():
        for key in val.bl_rna.properties.keys():     
            in_source_attribute = getattr(val,key)
            if not val.is_property_readonly(key):
                setattr(nodo_copiato, key, in_source_attribute)

Note: I want to clarify, because i don't want to create further confusion, that the question is not "How to copy an entire tree of nodes" but is how to access the values n.inputs [#].default_values (and other) in complete automation, as it is done in the line of my code in the part where the attributes are set via setattr / getattr As I want to get there by myself to the copy of a tree of knots, I am trying to study the situation, trying to better understand Blender's API thanks to the help of the community

| improve this question | | | | |
$\endgroup$
  • 3
    $\begingroup$ Could you give a specific example. Eg here is all the names of the bsdf inputs blender.stackexchange.com/a/160069/15543 $\endgroup$ – batFINGER Jan 23 at 14:11
  • 2
    $\begingroup$ The edit doesn't really help here. What you'd like to do and what's your question? You want to copy the whole tree or just some of the nodes? $\endgroup$ – brockmann Jan 23 at 15:36
  • 2
    $\begingroup$ From experience I'd say use a dict to store all the values and create the tree from scratch per execution. $\endgroup$ – brockmann Jan 23 at 16:09
  • 1
    $\begingroup$ I take it the big picture is "How to copy a node tree?" Or "How to copy a node" One suggested small change to above tipo_di_nodo = n.bl_rna.identifier Enjoying getting my Aussie accent around the Espanol $\endgroup$ – batFINGER Jan 24 at 4:31
  • 1
    $\begingroup$ Ok, thanks. If that operator is too hard to understand, take my advice and remove all nodes of the shader in the first place then create the shader each time from scratch to save you headaches. One big issue is that all default values of each node type are 0. There is no way to "reset" the values of any node and you have to create a new node to get the default values anyway... and really, the API of the node editor isn't the greatest part @Pastrokkio $\endgroup$ – brockmann Jan 24 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.