forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitychecks.py
242 lines (161 loc) · 7.07 KB
/
sanitychecks.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import maya.cmds as cmds
import maya.mel as mel
import sys
import pymel.core
import os
import time
#ATK sanitychecks
#Add file path metaData
#Hide assistants
#Set project here
#hide all imagePlanes
#Sets up distortion ST maps connections
def addFilePathMetaData():
# Adds metaData of saved name to the mayaFile metaData slot
nodeName = "defaultArnoldDriver.customAttributes"
filePath = cmds.file(q=1,sn=1)
mayaFile = {"type":"STRING","name":"mayaFile","value": filePath}
def addAttribute(nodeName, value):
#add an attribute
nextIndex = 0
if cmds.getAttr(nodeName, multiIndices= True):
nextIndex = cmds.getAttr(nodeName, multiIndices= True)[-1] + 1
cmds.setAttr(nodeName+'['+str(nextIndex)+']', "%s %s %s" % (value["type"],value["name"],value["value"]), type="string")
def changeAttribute(nodename, value):
for nodeNameIndex,i in enumerate(pymel.core.getAttr(nodeName)):
j= i.split(" ")
if len(j)>1:
if j[1] == 'mayaFile':
cmds.setAttr(nodeName+'['+str(nodeNameIndex)+']', "%s %s %s" % (value["type"],value["name"],value["value"]), type="string")
break
attributes=[]
for i in pymel.core.getAttr(nodeName):
j= i.split(" ")
if len(j)>1:
attributes.append( j[1])
if "mayaFile" in attributes:
metaDataAction = "mayaFile attribute existed, overwrote with new filename."
#change the attribute
changeAttribute(nodeName,mayaFile)
else:
#add an attribute
metaDataAction = "mayaFile attribute did not exist. Added it for you."
addAttribute(nodeName,mayaFile)
print "Added metaData"
#sys.stdout.write("metaData status: %s\n" %metaDataAction)
#Hide assistants
def hideAssistants():
renderlayers = cmds.ls(type="renderLayer")
print renderlayers
if u'default_light_rig:defaultRenderLayer' in renderlayers:
renderlayers.remove(u'default_light_rig:defaultRenderLayer')
print renderlayers
for layer in renderlayers:
print layer
#select the render layer
cmds.editRenderLayerGlobals(crl=layer)
wordIn = "Assistants"
sel = cmds.ls("*" + wordIn + "*", r=True)
cmds.select(sel)
cmds.hide(sel)
print "Hid Assistants"
def setProjectHere():
#set project here
scene = cmds.file(q=1,sn=1)
project = os.path.dirname(os.path.dirname(scene))
mel.eval('setProject("%s")' % project)
sys.stdout.write("Project location set: %s" %project)
def hideAllImageplanes():
renderlayers = cmds.ls(type="renderLayer")
print renderlayers
if u'default_light_rig:defaultRenderLayer' in renderlayers:
renderlayers.remove(u'default_light_rig:defaultRenderLayer')
print renderlayers
for layer in renderlayers:
cmds.editRenderLayerGlobals( currentRenderLayer=layer )
cmds.hide(mel.eval('ls -typ "imagePlane"'))
def checkRenderCamera():
# pick up here - check this is working
myCameras=cmds.ls(typ='camera',l=True)
renderableList=[]
for x in myCameras:
if cmds.getAttr(x+'.renderable'):
renderableList.append(x)
ll=len(renderableList)
if ll==0 or ll>=2:
print('Too many or no renderable cameras')
return 0
return 1
#-------------------------------------------------------------------------------
def executeThis():
#checks to see if distortion file exists:
distortionExists=True
matching = []
fileNodes=cmds.ls(typ='aiImage')
matching = [s for s in fileNodes if "UV_lensDistortionMap" in s]
if matching:
print "Lens Distortion UV_lensDistortionMap aiImage exists."
distortionExists=False
else:
print "Lens distortion UV_lensDistortionMap aiImage does not exist"
#Creates a dialogue with checkboxes for the above defs
if not checkRenderCamera():
cmds.error('Please pick a camera to render')
class createMyLayoutCls(object):
def __init__(self, *args):
pass
def show(self):
self.createMyLayout()
def createMyLayout(self):
#check to see if our window exists
if cmds.window('utility', exists = True):
cmds.deleteUI('utility')
# create window
self.window = cmds.window('utility', widthHeight = (200, 500), title = 'Pre-render checks', resizeToFitChildren=1, sizeable = False)
cmds.setParent(menu=True)
# create a main layout
mainLayout = cmds.columnLayout(w = 200, h = 200, cw = 10, rs = 8, co = ['both',2])
# Control - which things to do
self.AFPMDbox = cmds.checkBox('Add file path MetaData', value=True)
self.setProjectbox = cmds.checkBox('Set Project Here', value=True)
self.hideImageplanebox = cmds.checkBox('Hide imageplanes', value=False)
self.hideAssbox = cmds.checkBox('Hide Assistants', value=False)
self.distortion = cmds.checkBox('Setup distortion', value=distortionExists)
# Buttons that do things
btnDoSelected = cmds.button(label = 'Do Selected', width = 200, height = 40, c = self.GetSelectedNodes)
btnNoChanges = cmds.button(label = 'Make no changes', width = 200, height = 40, c = self.noChangesMade)
# show window
cmds.showWindow(self.window)
def GetSelectedNodes(self,*args):
hideAss = cmds.checkBox(self.hideAssbox,q = True, v = True)
AFPMD = cmds.checkBox(self.AFPMDbox,q = True, v = True)
setProject = cmds.checkBox(self.setProjectbox,q = True, v = True)
hideImageplanes = cmds.checkBox(self.hideImageplanebox,q = True, v = True)
distortion = cmds.checkBox(self.distortion,q = True, v = True)
print hideAss
if hideAss == True:
hideAssistants()
print AFPMD
if AFPMD == True:
addFilePathMetaData()
print setProject
if setProject == True:
setProjectHere()
print hideImageplanes
if hideImageplanes == True:
hideAllImageplanes()
print distortion
if distortion == True:
import setupMayaLensDistortionOptions
reload(setupMayaLensDistortionOptions)
setupMayaLensDistortionOptions.doSomething()
if cmds.window('utility', exists = True):
cmds.deleteUI('utility')
mel.eval('SubmitJobToDeadline')
def noChangesMade(self,*args):
cmds.deleteUI('utility')
mel.eval('SubmitJobToDeadline')
print "No changes made, proceeding to Deadline Submission."
b_cls = createMyLayoutCls()
b_cls.show()
executeThis()