forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shotgun_accessShotInfo
386 lines (298 loc) · 12.9 KB
/
Shotgun_accessShotInfo
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# Maya Shotgun sync tool Mark Bailey 180219
# Shotgun: Access shot info
# Actual code for 'Set Render Output Naming' python button
"""
To Do:
* Add option for double-res
* If changing FPS, keep keys at current frames (this may be hard)
Pipeline's Mel that does hardcoded things:
# If this has to be .mel, make the mel run a separate python (?)
// Rendersettings
global proc setRenderSettings(){
setAttr "defaultResolution.width" 2704;
setAttr "defaultResolution.height" 1520;
//setAttr "defaultResolution.pixelAspect" 1.0; // Not needed as this is driven by the line below.
setAttr "defaultResolution.deviceAspectRatio" 1.779; // Added this line to drive the pixelAspect -- Toby 6/6/18
setAttr "defaultResolution.aspectLock" 1.0;
setMayaSoftwareFrameExt(3,0);
currentUnit -time film;
setAttr -type "string" "defaultRenderGlobals.imageFilePrefix" "<Scene>/<RenderLayer>/<Scene>.<RenderLayer>.<RenderPass>";
print("Render settings applied for SHR: Res 2704 x 1520 | pixelAspect 1.0 | aspectLock 1.0 | 24fps.\n");
}
setRenderSettings();
ile
https://forums.autodesk.com/t5/maya-programming/load-render-setup-json-file-with-python/td-p/6762688
# ask to setup hdr,key,rim,fill lightrig (with lightgroups)
Useful paths:
"/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/render_settings"
"/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/render_setups"
"/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/atk_defaultLights_v001.ma"
"/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/render_settings/atk_arnoldSettings_v003.json"
#1.1:
Dialogue with checkboxes - all on by default.
"""
#Setting up the load render globals preset
import maya.app.renderSetup.model.renderSetup as renderSetup # for renderlayers
import maya.app.renderSetup.model.renderSettings as renderSettings # for renderGlobals
import json
#Setting up all the other bits
import sgtk
import os
import sys
import re
import maya.cmds as cmds
import maya.mel as mel
# my aovs script
import aovSettings
reload(aovSettings)
# Get CustomQuery
sys.path.append(r"/mnt/pipeline/ATK_PIPELINE/atk-api")
from atk_shotgun.ShotgunTankAccess import CustomQuery
reload(CustomQuery)
custom_query_obj = CustomQuery.Custom_Query()
# Get Tank access
from atk_shotgun.ShotgunTankAccess import ShotgunTankAccess
reload(ShotgunTankAccess)
sta= ShotgunTankAccess.Shotgun_Tank_Access()
sg= sta.get_sg()
def getOpenSceneFilePath():
scene = cmds.file(q=1,sn=1)
project = os.path.dirname(os.path.dirname(scene))
return scene
def get_frame_rate_by_project_name(project_name):
fields = ['sg_fps']
filters = [['name', 'is', project_name]]
result = sg.find_one("Project", filters, fields)
result = result["sg_fps"]
if result is None or result == 0:
return 24
else:
return result
def getShotDetails(scenePath):
code = ""
sequence_entity = ""
from atk_shotgun.ShotgunTankAccess import ShotgunTankAccess
reload(ShotgunTankAccess)
sta= ShotgunTankAccess.Shotgun_Tank_Access()
sg= sta.get_sg()
basename= os.path.basename(scenePath)
regex = r"(\S*?[0-9])_[a-zA-Z]"
matches = re.search(regex, basename)
if matches:
code= matches.groups()[0]
sequence_entity= sg.find("Shot", [["code", "is", code]],['code'])[-1]
shot_id = sequence_entity["id"]
code = sequence_entity["code"]
print sequence_entity
return shot_id, code
def get_shot_resolution_by_id(shot_id):
sg_entity_type = "Shot"
sg_filters = [["id", "is", shot_id]]
fields = ['sg_resolution']
data = sg.find_one(sg_entity_type, filters=sg_filters, fields=fields)
print data
if data is None or data["sg_resolution"] is None:
return False
else:
return data["sg_resolution"]
def get_aspect_ratio_from_project_resolution_by_name(project_name):
sg_entity_type = "Project"
sg_filters = [["name", "is", project_name]]
fields = ['sg_resolution']
print fields
data = sg.find_one(sg_entity_type, filters=sg_filters, fields=fields)
if data:
#data = float(data["sg_resolution"].split(" ")[-1][:-2])
data = data["sg_resolution"]
return data
def get_project_id_by_name(project_name):
fields = ['id']
filters = [["name", "is", project_name]]
project = sg.find_one("Project", filters, fields)
return project
def get_aspect_ratio_from_project_resolution_by_id(project_id):
sg_entity_type = "Project"
sg_filters = [["id", "is", project_id]]
fields = ['sg_resolution']
data = sg.find_one(sg_entity_type, filters=sg_filters, fields=fields)
print data
if data:
aspect = float(data["sg_resolution"].split(" ")[-1][:-2])
return data, aspect
def checkFps(scenePath, project_name ):
"""
currentUnits (from docs)
game: 15 fps
film: 24 fps
pal: 25 fps
ntsc: 30 fps
show: 48 fps
palf: 50 fps
ntscf: 60 fps
May be of help:
https://www.programcreek.com/python/example/107820/maya.cmds.currentUnit
"""
#scenePath = getOpenSceneFilePath() #moved this outside the function
if scenePath == "":
cmds.error( "Scene is not saved. Use Shotgun to save your scene first." )
# project_name = (str(scenePath).split("/")[3]) # projectname is always after projects/ - moved outside the function
# Checks to see if the FPS matches shotgun
fps = get_frame_rate_by_project_name(project_name)
# the madness way?
sceneTime = cmds.currentUnit(query=True, time=True)
if sceneTime == "game":
sceneTime = 15
if sceneTime == "film":
sceneTime = 24
if sceneTime == "pal":
sceneTime = 25
if sceneTime == "ntsc":
sceneTime = 30
if sceneTime == "show":
sceneTime = 48
if sceneTime == "palf":
sceneTime = 50
if sceneTime == "ntscf":
sceneTime = 60
if int(fps) == sceneTime:
print "Scene FPS matches shotgun"
else:
print "Project fps {} may not match scene fps: {}".format(str(fps),str(sceneTime))
fixFps = True
return fixFps
def setResolution(pxRes, pyRes, pixelAspect=1.0):
cmds.setAttr("defaultResolution.aspectLock", 0) # unlocks ratio
#Calculates the device aspect since pixel aspect isn't an actual attribute.
device_aspect = float(int(pxRes) * pixelAspect)/float(int(pyRes))
#Set the Lock Device Aspect Ratio. IMPORTANT!
#If you don't do this it won't work.
cmds.setAttr("defaultResolution.lockDeviceAspectRatio", 1)
#Set width, height, and aspect ratio.
cmds.setAttr("defaultResolution.width", pxRes)
cmds.setAttr("defaultResolution.height", pyRes)
cmds.setAttr("defaultResolution.deviceAspectRatio", device_aspect)
cmds.setAttr("defaultResolution.aspectLock", 1) # locks ratio
def get_shot_frame_range_by_shot_code(code):
sg_filters = [["code", "is", code]]
fields = ['sg_cut_in', 'sg_cut_out']
print fields
data = sg.find_one("Shot", filters=sg_filters, fields=fields)
if data is None or data["sg_cut_in"] is None or data["sg_cut_out"] is None:
return False
else:
return int(data["sg_cut_in"]), int(data["sg_cut_out"])
def createAovs():
setupAOVs = ""
setupAOVs = cmds.confirmDialog(
title='AOVs', message='Run AOV setup?',
button=['Yes','No'], defaultButton='Yes',
cancelButton='No', dismissString='No'
)
if setupAOVs == "Yes":
aovSettings.aovSettings()
def importDefaultLights():
importLights = cmds.confirmDialog(
title='AOVs', message='Import default Wild Bill lights\nHDR, Key, Rim, Fill + lightgroups',
button=['Yes','No'], defaultButton='Yes',
cancelButton='No', dismissString='No'
)
if importLights == "Yes":
fileExists = False
fileExists = cmds.file( "/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/atk_defaultLights_v001.ma", q=True, ex=True )
if fileExists == True:
cmds.file( "/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/atk_defaultLights_v001.ma", i=True, type='mayaAscii', namespace='lightRig' )
print "Imported: /mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/atk_defaultLights_v001.ma"
else:
cmds.error( "LightRig file not found: /mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/atk_defaultLights_v001.ma - Contact your supervisor." )
#---------------Code here-------------------------------------------------------------------------
# Load atk_arnoldSettings .json file
#prefs.loadUserPreset()
#prefs.getGlobalPresets("arnold")
import maya.app.renderSetup.views.renderSetupPreferences as prefs
prefs.loadGlobalPreset("atk_arnoldSettings_v003")
# Full Path to the globals preset it's importing "/mnt/pipeline/ATK_PIPELINE/maya/modules/WB/presets/render_settings/atk_arnoldSettings_v003.json"
#----------------- Check the Resolution is correct
# Setup summary
fpsSummary = ""
resolutionSummary = ""
startEndFrameSummary = ""
# Get shot resolution by shot ID
fixRes = False
scenePath = ""
scenePath = getOpenSceneFilePath()
if scenePath:
project_name = (str(scenePath).split("/")[3])
else:
cmds.error( "Scene not saved. Save scene via Shotgun > file save first." )
shot_id = ""
shot_id = getShotDetails(scenePath)[0]
xRes = ""
yRes = ""
if get_shot_resolution_by_id(shot_id) != False:
xRes,yRes = ((get_shot_resolution_by_id(shot_id)).split(" ")[1]).split("x")
print "Shot res is {}x{}".format(xRes,yRes)
else:
print "Using project res as shot res"
# Get project resolution by project ID
project_id = (get_project_id_by_name(project_name))["id"]
print project_id
projectRes, aspect = get_aspect_ratio_from_project_resolution_by_id(project_id)
projectRes = str(projectRes["sg_resolution"])
pxRes, pyRes = ((projectRes).split(" ")[1]).split("x")
# Get local resolution
localxRes = cmds.getAttr("defaultResolution.width")
localyRes = cmds.getAttr("defaultResolution.height")
# Check and set the resolution (remember to unlock aspect and then lock it)
print "Shot Resolution : "+ str(xRes), str(yRes)
print "Project Resolution : "+ str(pxRes), str(pyRes)
print "Local scene Resolution : "+ str(localxRes), str(localyRes)
# Forces shot res is res field isn't False (empty)
if xRes == pxRes and yRes == pyRes and localxRes == pxRes and localyRes == pxRes and localxRes == xRes and localyRes == yRes:
print "Local scene resolution matches shot and project resolution. Moving on."
else:
if get_shot_resolution_by_id(shot_id) == False:
print "SG Shot resolution field is empty. Matching project resolution"
if get_shot_resolution_by_id(shot_id) != False:
if localxRes != xRes or localyRes != yRes:
print "Setting local shot res to {} x {}. Forcing pixel aspect to 1.0".format(xRes, yRes),
setResolution(int(xRes), int(yRes), pixelAspect=1.0)
resolutionSummary = "| Set resolution to project res: {} x {} ".format(str(xRes), str(yRes))
if get_shot_resolution_by_id(shot_id) == False:
if localxRes != pxRes or localyRes != pyRes:
print "Setting res to project res: {} x {}. Forcing pixel aspect to 1.0".format(pxRes, pyRes),
setResolution(int(pxRes), int(pyRes), pixelAspect=1.0)
resolutionSummary = "| Set resolution to project res: {} x {} ".format(str(pxRes), str(pyRes))
#----------------- CHECKS PROJECT FPS
fixFps = checkFps(scenePath, project_name)
if fixFps == True:
print "Setting fps to project fps. Warning - Keys may have changed"
fpsSummary = "Set project fps, WARNING - existing keys may have changed "
scenePath = getOpenSceneFilePath()
project_name = (str(scenePath).split("/")[3]) # projectname is always after projects/
fps = get_frame_rate_by_project_name(project_name)
fps = str(int(fps))+"fps"
cmds.currentUnit( time=fps )
#----------------- Set start-end-frame (especially changing fps will move the start-end frames)
code = getShotDetails(scenePath)[1]
sg_startFrame, sg_endFrame = get_shot_frame_range_by_shot_code(code)
fStart = int(cmds.getAttr('defaultRenderGlobals.startFrame'))
fEnd = int(cmds.getAttr('defaultRenderGlobals.endFrame'))
if fStart != sg_startFrame or fEnd != sg_endFrame:
cmds.setAttr("defaultRenderGlobals.startFrame", sg_startFrame)
cmds.setAttr("defaultRenderGlobals.endFrame", sg_endFrame)
cmds.playbackOptions(min=sg_startFrame,max=sg_endFrame)
cmds.playbackOptions(animationStartTime=sg_startFrame)
cmds.playbackOptions(animationEndTime=sg_endFrame)
startEndFrameSummary = "| Set render-range to {}-{} ".format(sg_startFrame, sg_endFrame)
#------------- OPTIONAL SETTINGS
# Aovs
# Load project renderGlobals preset
# Create and set up lightgroup aovs (import scene from assets)
#THIS NEEDS TO CHECK FOR AOVS BEFORE RUNNING
# Create AOVs?
createAovs()
#THIS ALSO NEEDS TO CHECK FOR THE DEFAULT LIGHTRIG FIRST
# Import default lightRig?
importDefaultLights()
#Summary output
print fpsSummary+resolutionSummary+startEndFrameSummary,