1
$\begingroup$

After many frustrating days I've managed to get my bake script to not crash, and now I'm banging my head against a wall to have it work with the new BSDF shaders.

I knew the inputs were different, but one thing I did not expect is that the Color Mix node I now have to feed the Diffuse and Subsurface into would give me trouble.

>>> mix = bpy.data.materials["Fingernails"].node_tree.nodes["DS_Mix"]
>>> for i, o in enumerate(mix.outputs):
...     1, o.name
...     i, o.name
...     
(1, 'Result')
(0, 'Result')
(1, 'Result')
(1, 'Result')
(1, 'Result')
(2, 'Result')
(1, 'Result')
(3, 'Result')

The node itself only has one output you can interact with, so how does it have all these hidden ones? And how am I supposed to cal these in Python to make links?

mat.node_tree.links.new(ds_mix.outputs[2], baked_BSDF.inputs[0]) worked yesterday, but now it's not.

Update

I've made some progress after scouring around and finding the following pages:

And I now have a thing that makes the intended link:

tree = bpy.context.object.active_material.node_tree
#other defs
baked_BSDF = bpy.data.materials["Skin"].node_tree.nodes["Baked_BSDF"]
ds_mix = bpy.data.materials["Skin"].node_tree.nodes["Diff_Sub_Mix"]
#other stuff going on
def get_socket(sockets, identifier):
                for socket in sockets:
                    if socket.identifier == identifier:
                        return socket
tree.links.new(get_socket(ds_mix.outputs, 'Result_Color'), baked_BSDF.inputs['Base Color'])

So while this will probably work for most of what I'm currently tryign to do, I may come across some other node outputs that I'm not going to know the names of, and I can't just spend days guessing at each one.

So does anybody know how I can call the actual names up so I can put them in my code?

$\endgroup$

1 Answer 1

1
$\begingroup$

I found it.

From this question and some experimenting I discovered how to do this in the python console.

>>> mix = bpy.data.materials["Skin"].node_tree.nodes["Diff_Sub_Mix"]
>>> for i, o in enumerate(mix.outputs):
...     i, o.identifier
...     
(0, 'Result_Float')
(1, 'Result_Vector')
(2, 'Result_Color')
(3, 'Result_Rotation')

>>> 

Should also work for the inputs, and the other fields and values of the nodes, if you can find them. I really wish the blender devs would actually include this kind of information in the docs.

$\endgroup$
14
  • $\begingroup$ inputs and outputs are dictionaries that you can access by name or index: outputs['name'] or outputs[0]. You can also outputs.get('name') to check if it exists. $\endgroup$
    – lemon
    Commented Mar 7 at 6:55
  • $\begingroup$ Can you provide a complete example of that? I'm always keen on more efficient ways to do things like that. If it works I'll update the answer to include it. $\endgroup$ Commented Mar 7 at 15:21
  • $\begingroup$ I don't know where to paste it as text for you, but here you are: i.sstatic.net/eSuAv.png $\endgroup$
    – lemon
    Commented Mar 7 at 15:35
  • $\begingroup$ Oh, that's what you meant. That's interesting but I was hoping you had a more efficient way of finding the names to then use in the script. $\endgroup$ Commented Mar 7 at 15:49
  • $\begingroup$ Either you already know the names (or indices) and just 'sockets[name]'... or what else? $\endgroup$
    – lemon
    Commented Mar 7 at 15:51

You must log in to answer this question.

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