import Blender
# ---------------------------
# Dictionnary Object table
# ---------------------------
# 2 entries :
# --> first the list of rvb colors, 3 floats rounded to
0.001
# as lists are not "hashable",
and can not be used in a dictionnary,
# they are translated into strings
.
# CAUTION : always 3 digits at
the right of the point,
# not "1.0" but "1.000".
#
# --> in second the material names
#
# 'rvb color'
: 'metal name'
# ---------------------------
TABLE={
'0.637,1.000,1.000':
'metal_',
'0.001,0.005,1.000':
'metal_02',
'0.001,0.005,1.000':
'metal_03',
'0.001,0.005,1.000':
'metal_04',
'0.001,0.005,1.000':
'metal_05',
'0.001,0.005,1.000':
'metal_06',
'0.001,0.005,1.000':
'metal_07',
'0.001,0.005,1.000':
'metal_08',
'0.001,0.005,1.000':
'metal_09',
'0.001,0.005,1.000':
'metal_10',
'0.001,0.005,1.000':
'metal_11',
'0.001,0.005,1.000':
'metal_12',
'0.001,0.005,1.000':
'metal_13',
'0.001,0.005,1.000':
'metal_14'
}
# ----------------------------
# Get all the meshes :
# ----------------------------
ME=[m for m in Blender.Object.Get() if m.getType()=='Mesh']
# ----------------------------
# in this list find ...
# ----------------------------
for m in ME:
# ----------------------------
# ... if, in the data ,...
# ----------------------------
me=m.getData()
# ----------------------------
# ...the list of material contents ...
# ----------------------------
for c in me.materials :
# ----------------------------
# ... a color then translate this
color in a usable string .
# ----------------------------
color ="%.3f,%.3f,%.3f"%(round(c.rgbCol[0],3),round(c.rgbCol[1],3),round(c.rgbCol[2],3))
print color,TABLE.keys()
# ----------------------------
# Compare this string with the
dictionnary keys
# ----------------------------
if color in TABLE.keys():
# ----------------------------
# if an identical color exists, replace the material by the other
# ----------------------------
me.materials[me.materials.index(c)]=Blender.Material.Get(TABLE[color])
#------------
# replace the original mesh bu the modified one .
#------------
me.update()
Blender.Window.RedrawAll()
|