-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkSaveToDepotVray.py
126 lines (121 loc) · 4.63 KB
/
mkSaveToDepotVray.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
# ------------------- Written by: Mike Kirylo, ------------------------------------------------
# ------------------- for Zoic Studios
# ------------------- dec 13 2011
# ------------------- saves maya content to the depot
# -------imports ------------------------------------
import sys
import os
import maya.cmds as cmds
import maya.mel as mel
import maya
import zlib
import zipfile
import maya.cmds as cmds
import shutil
import glob
import subprocess
sys.path.append( 'Q:/Tools/Shotgun/Scripts/python/' )
# --------------------------------------------------------
# global variables
# --------------------------------------------------------
RenderableCam = []
DJV_LS = "Q:/Tools/DJV/32/djv-0.8.3.2/bin/djv_ls.exe"
# --------------------------------------------------------
# find renderable camera
# --------------------------------------------------------
def mkRenderCam():
cameras = cmds.ls(type= "camera")
for cam in (cameras):
camRenderable = cmds.getAttr (cam+".renderable")
if camRenderable == True:
RenderableCam.append(cam)
if RenderableCam == [] :
cmds.warning ("no renderable cameras in scene")
return RenderableCam
# --------------------------------------------------------
# Zip scene file
# --------------------------------------------------------
def zipScene():
fileName = maya.cmds.file(q=True, sceneName=True)
# If the scene has not been saved
if (fileName==""):
cmds.warning( "file not saved" )
# get the default character encoding of the system
theLocale = cmds.about(codeset=True)
# get a list of all the files associated with the scene
files = maya.cmds.file(query=1, list=1, withoutCopyNumber=1)
# create a zip file named the same as the scene by appending .zip
zipFileName = files[0].replace( '.mb', '.zip' )
zip=zipfile.ZipFile(zipFileName, 'w', zipfile.ZIP_DEFLATED)
# add each file associated with the scene, including the scene
# to the .zip file
for file in files:
name = file.encode(theLocale)
zip.write(name)
zip.close()
# output a message whose result is the name of the zip file newly created
newZip = zipFileName.split("/")
cmds.confirmDialog(m=newZip[-1]+" was created", cb = "cancel")
mkThumbNail(files,zipFileName)
# mkIngestionDir(zipFileName,'.zip')
# --------------------------------------------------------
# make thumbnail
# --------------------------------------------------------
def mkThumbNail(fileName,zipfile):
# get file name and path for thumbnail
# vrayOn = 'source "Q:/Tools/maya/2012/scripts/mel/Misc/awLoadVray.mel"; awLoadVray;'
# mel.eval(vrayOn)
vrayEnable = 'source "Q:/Tools/maya/2012/scripts/mel/Misc/awLoadVray.mel"; awVrayOn;'
mel.eval(vrayEnable)
files = fileName
thumbFileName = files[0].replace( '.mb', '.jpg' )
print thumbFileName
currentCam = mkRenderCam()
if currentCam == " ":
cmds.warning ("no renderable camera")
# render and save image
VRAYRENDER ='RenderIntoNewWindow;'
mel.eval(VRAYRENDER)
editor = 'renderView'
cmds.renderWindowEditor(editor, e = True, writeImage = thumbFileName)
cmd = DJV_LS + ' -columns 500 "' + thumbFileName + '"'
proc = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, )
# newFolder = mkIngestionDir(thumbFileName,'.jpg')
# mkIngestionDir(zipfile,'.zip')
# DepotIngestion()
# removeFolder(newFolder)
# --------------------------------------------------------
# copy files to ingestion dir
# --------------------------------------------------------
def mkIngestionDir(source,type):
mkFile = source
filename =source.split("/")
filename = filename[-1]
mkSource =source.split("/")
mkSource = mkSource[-1]
mkSource = mkSource.replace( type, "" )
mkFolder =source.split("/")
mkFolder.pop(-1)
mkFolder = "/".join(mkFolder)
mkFolder=mkFolder+"/"+mkSource
if os.path.exists( mkFolder ) == False:
os.makedirs( mkFolder )
copycmd = 'sysFile -copy'+' '+'"'+mkFolder+'/'+ filename +'"'+' ' + '"'+ mkFile+'"'+';'
mel.eval (copycmd)
dst = "Q:/Tools/Nearline/ingestion/3dModels"
delcmd = 'sysFile -delete'+' "'+mkFile+'";'
mel.eval (delcmd)
createdirCmd = 'sysFile -makeDir'+' '+'"'+dst+'/' +mkSource+'/"'
mel.eval(createdirCmd)
cpyDepotCmd = 'sysFile -mov'+' '+'"'+dst+'/' +mkSource+'/'+filename +'"'+' ' + '"'+mkFolder+'/'+ filename +'"'+';'
mel.eval (cpyDepotCmd)
print "copied "+filename+" to depot"
removeEmptydir = 'sysFile -removeEmptyDir'+' '+'"'+mkFolder+'/";'
mel.eval (removeEmptydir)
cmds.confirmDialog(m=filename+" ready for upload", cb = "cancel")
return mkFolder
def DepotIngestion():
from sgCronDepotTextureIngest import main
main(*sys.argv)
def removeFolder(folderpath):
os.rmdir(folderpath)