-
Notifications
You must be signed in to change notification settings - Fork 2
/
toggleHoldout.py
75 lines (58 loc) · 2.21 KB
/
toggleHoldout.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
70
71
72
73
74
75
# Author : HYUK KO | [email protected] | github.com/kohyuk91
import maya.cmds as mc
def getObjectType(sel):
try:
objectType = mc.objectType(sel) # Get object type.
except:
objectType = "transform" # If there is no shape node pass "transform".
return objectType
def isOneImageplaneSelected(shapeList):
shapeListSize = len(shapeList)
if not 0 < shapeListSize < 2:
return False
objectType = getObjectType(shapeList[0])
if objectType == "imagePlane":
return True
else:
return False
def getShapeList(transformList):
shapeList = []
for transform in transformList:
shape = mc.listRelatives(transform, shapes=True, fullPath=True)[0]
shapeList.append(shape)
return shapeList
def main():
selGeoTransList = mc.ls(selection=True, long=True)
selGeoShapeList = getShapeList(selGeoTransList)
selGeoShapeListSize = len(selGeoShapeList)
if selGeoShapeListSize == 0 or isOneImageplaneSelected(selGeoShapeList): # If nothing is selected toggle all geometry in scene.
holdoutGeoExists = False
geoList = mc.ls(geometry=True, long=True) # Get list of geometric Dag objects in scene.
for geo in geoList:
try:
holdoutGeoExists = mc.getAttr(geo + '.holdOut')
except:
pass
if holdoutGeoExists: # If Holdout Geometry exists in scene...
for geo in geoList:
try:
mc.setAttr(geo + '.holdOut', 0) # Turn off holdout for all geometry in scene
except:
pass
return
if not holdoutGeoExists: # If there is no Holdout Geometry in scene...
for geo in geoList:
try:
mc.setAttr(geo + '.holdOut', 1) # Turn on holdout for all geometry in scene
except:
pass
return
elif selGeoShapeListSize >= 0:
for selGeoShape in selGeoShapeList:
try:
toggleState = mc.getAttr(selGeoShape + '.holdOut')
mc.setAttr(selGeoShape + '.holdOut', (not toggleState))
except:
pass
if __name__ == "__main__":
main()