-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaterialImport.py
69 lines (45 loc) · 1.61 KB
/
MaterialImport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import c4d
from c4d import gui
from random import randint
#Welcome to the world of Python
def main():
#gui.MessageDialog('Hello World!')
doc = c4d.documents.GetActiveDocument()
materialList = doc.GetMaterials()
for material in materialList:
materialName = material.GetName()
#print (materialName)
r = randint(0, 255)
g = randint(0, 255)
b= randint(0, 255)
print (r, g, b)
layer = CreateLayer(materialName, c4d.Vector(r, g, b))
material.SetLayerObject(layer)
#material.InsertUnder(layer)
#print(material.GetLayerObject())
def CreateLayer (layername, layercolor):
doc = c4d.documents.GetActiveDocument()
root = doc.GetLayerObjectRoot() #Gets the layer manager
LayersList = root.GetChildren() #Get Layer list
# check if layer already exist
layerexist = False
for layer in LayersList:
name = layer.GetName()
if (name == layername):
return layer
c4d.CallCommand(100004738) # New Layer
c4d.EventAdd()
#rename new layer
LayersList = root.GetChildren() #redo getchildren, because a new one was added.
for layer in LayersList:
name = layer.GetName()
if (name == "Layer"):
layer.SetName(layername)
layer.SetBit(c4d.BIT_ACTIVE) # set layer active
layer[c4d.ID_LAYER_COLOR] = layercolor
layerData = {'color': layercolor, 'solo' : False}
layer.SetLayerData(doc, layerData)
c4d.EventAdd()
return layer
if __name__=='__main__':
main()