here is example of what i got using the master mat list
sorry i added the wrong little snippet here
so i replaced it with a simple example
i tried the dir name inside sc ript like show near the end
and it does not print anything !
# Weave diagonales lines
import bpy
from bpy.props import *
from mathutils import *
from math import *
row1 =400
col1 =500
####
print ()
print ('Weave diagonales lines')
print ()
print ('Render engine =',bpy.context.scene.render.engine)
if bpy.context.scene.render.engine=='BLENDER_RENDER':
print ('Render is = BLENDER_RENDER')
bpy.context.scene.render.engine="CYCLES"
print ('Converted to BLENDER_CYCLES')
else:
print ('Render is = CYCLES')
print ()
"""
dir(mats)
['__bool__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__doc__', '__getattribute__',
'__getitem__', '__iter__', '__len__', '__module__', '__setattr__', '__setitem__', '__slots__', 'bl_rna',
'find', 'foreach_get', 'foreach_set', 'get', 'is_updated', 'items', 'keys', 'new', 'remove', 'rna_type',
'tag', 'values']
"""
mats = bpy.data.materials
sc = bpy.context.scene
for cmat in mats:
print (' cmat =',cmat)
cmat.use_nodes=True
TreeNodes=cmat.node_tree
links = TreeNodes.links
shader=''
shmix=''
shtsl=''
Add_Emission=''
Add_Translucent=''
Mix_Alpha=''
sT=False
lock=True
# print (' mat=',len(mats))
# print (' mat=',len(mats),' name =',mats.name)
# ShaderNode(Node) Page 949
print ()
for n1 in TreeNodes.nodes:
if n1.type == 'OUTPUT_MATERIAL':
if n1.label == 'Lock':
print (' being lock')
lock=False
if lock:
for n2 in TreeNodes.nodes:
TreeNodes.nodes.remove(n2)
if not shader :
row1=400
col1=500
# Material node
shout = TreeNodes.nodes.new('OUTPUT_MATERIAL') # This add a new material output node
shout.location = col1,row1
# Diffuse shader node
shaderdiff1 = TreeNodes.nodes.new('BSDF_DIFFUSE') # This add a new BSDF_DIFFUSE node
shaderdiff1.location =col1-400, row1
# shaderdiff1.operation =" "
# Glossy shader node
shadergloss1 = TreeNodes.nodes.new('BSDF_GLOSSY') # This add a new BSDF_GLOSSY node
shadergloss1.location = col1-400, row1-200
# Mix shader node
shadermix1 = TreeNodes.nodes.new('MIX_SHADER') # This add a new MIX_SHADER node
shadermix1.location = col1-200, row1
shadermix1.name = "Mix1"
links.new(shadermix1.outputs[0],shout.inputs[0])
links.new(shaderdiff1.outputs[0],shadermix1.inputs[1])
links.new(shadergloss1.outputs[0],shadermix1.inputs[2])
# MIX_RGB node
shaderMIX_RGB1 = TreeNodes.nodes.new('MIX_RGB') # This add a MIX_RGB node
shaderMIX_RGB1.location = col1-600, row1+100
# shaderMIX_RGB1.operation="MULTIPLY"
dir('shaderMIX_RGB1')
# Add color to shaders
# This sets the colors
shaderdiff1.inputs['Color'].default_value=cmat.diffuse_color.r,cmat.diffuse_color.g,cmat.diffuse_color.b,1
if shaderdiff1.type=='BSDF_DIFFUSE':
# shader.inputs['Roughness'].default_value=cmat.specular_intensity
shaderdiff1.inputs['Roughness'].default_value=0.3333 # This sets the value of the BSDF_DIFFUSE
problem is that this is adding nodes to all mat in master mat list !
which is not what i want !
now how do you change this for using object’s list of mat ?
here is sample file
znodecyclesimple1.blend (412 KB)
thanks