Need help w/ old script: Change diffuse shader to emission shader without affecting shader color

Hi, I found the exact thing I need in a Stack Exchange question.

Problem is it’s old and I think some of the terms have changed as it’s not running. I tried changing

if obj.select:

to

if obj.select_set:

and

if node.type=='BSDF_DIFFUSE':

to

if node.type=='Principled BSDF':

but these changes didn’t do anything. Would it be possible to get any help on this?

In the console, entering the first line and hitting the tab button on the keyboard:

>>> ob.select_
              get(
              set(
>>> ob.select_get(
select_get()
Object.select_get(view_layer=None)
Test if the object is selected. The selection state is per view layer
>>> ob.select_get()
True

Note that the ob.select_get() returned a boolean, so my bet is that is what needs to take the place of the “if obj.select_set:” statement.

As for the node issue, I am not so knowledgeable on nodes, the code runs fine in the text editor after modifying the if statement, so I am not sure why the node type would not be changing. One thing you could try is manually changing the node, and watching in the info window what code it uses to do the switch, if it uses different code, that is likely the issue, if it does not, there is a deeper issue, also, Blender is extremely picky about what it can do based on the MODE it is in, so it may just be that the mode needs to be different.

1 Like

Awesome thank you. Yes “select_get()” was the answer. And the node.type==‘BSDF_PRINCIPLED’

1 Like