forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createShaderKeeper
49 lines (32 loc) · 1.23 KB
/
createShaderKeeper
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
"""
Creates shaderKeeper.ma
Select geo you want shaders-on-Cubes exported as a .ma shaderKeeper group
MB 010917
"""
import maya.cmds as cmds
import sets
objects = cmds.ls(sl=True)
objectName = str(cmds.ls(sl=True))
skCubes = []
#name = cmds.polyCube( r=1, name=objectName[3:-2] +"_shaderKeeper" )
for i in objects:
object = str(i)
# Gets the shader attached to the object
shaders = cmds.listConnections(cmds.listHistory(i,f=1),type='shadingEngine')
print shaders
#remove duplicates using sets.Set
removeDuplicates = sets.Set(shaders)
for each in removeDuplicates:
# Makes a Cube with the name of the selected object and assigns i's shader
shading_engine,polyCube = cmds.polyCube(w=0.0001, d=0.0001, h=0.0001, sx=0, sy=0, sz=0, name=object+"_"+each+"_shaderKeeper" )
skCubes.append(shading_engine)
cmds.select(shading_engine)
cmds.hyperShade( assign=each )
cmds.select(skCubes)
shaderKeeperGroup = cmds.group(n='shaderKeepers' )
multipleFilters = "Maya ASCII (*.ma)"
filename = cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2)
cmds.file( rename=filename[0] )
cmds.file( es=True, sh=True, type='mayaAscii')
print "Saved "+ str(filename)
#end