def file_open(self, filepath): """ Open the specified file. """ # Remove backslashes from path as this causes issues on Windows... filepath = os_wrapper.absolutePath(filepath) # print("Loading: %s" % filepath) # Hide UI to prevent is stealing focus from Houdini's own dialog... self.file_open_ui.hide() try: hou.hipFile.load(file_name=filepath) self.set_hip_and_job_vars( set_hip_explicit=os.path.dirname(filepath)) return filepath except hou.OperationFailed as e: dialog = prompt.dialog() dialog.display(str(e), "Error Opening File", conf=True) return False except hou.LoadWarning as e: dialog = prompt.dialog() dialog.display(str(e), "Warning", conf=True) return False
def gather(gatherPath): gatherPath = os.path.expandvars(gatherPath) # Instantiate data classes assetData = metadata.Metadata(os.path.join(gatherPath, 'asset_data.json')) try: assetPblName = assetData.get_attr('asset', 'assetPblName') asset = assetData.get_attr('asset', 'asset') assetExt = assetData.get_attr('asset', 'assetExt') requires = assetData.get_attr('asset', 'requires') # Check if ICSet for required asset exists in scene if not mc.objExists('ICSet_%s' % requires): verbose.animRequires(requires) return # Check if ICSet with same name exist in scene and delete it if mc.objExists('ICSet_%s' % assetPblName): mc.delete('ICSet_%s' % assetPblName) # Get published asset from the gatherPath animFile = os.path.join(gatherPath, '%s.%s' % (assetPblName, assetExt)) if not os.path.isfile(animFile): verbose.noAsset() return # Load ATOM animation plugin if needed mc.loadPlugin('atomImportExport', qt=True) # Gathering... allObjLs = mc.listRelatives(asset, ad=True, f=True, typ='transform') if allObjLs: allObjLs.append(asset) else: allObjLs = [asset] # Delete old animation mayaOps.deleteChannels(allObjLs, hierarchy=True) mc.select(asset, r=True) mc.file( animFile, typ='atomImport', op= ';;targetTime=3; option=replace; match=hierarchy;;selected=childrenToo;;search=;replace=;prefix=;suffix=;mapFile=', i=True, ra=True) # Generate icSet dataSet = mayaOps.icDataSet(asset, assetData) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) dialogTitle = 'Gather Warning' dialogMsg = 'Errors occured during asset update.\nPlease check console for more information.\n\n%s' % traceback.format_exc( ) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def show(): dialog = prompt.dialog() title = '%s - %s' % (os.environ['IC_JOB'], os.environ['IC_SHOT']) message = """Shot info: Job: %s Shot: %s User: %s Linear unit: %s Angular unit: %s Time unit: %s Frame range: %s-%s FPS: %s Resolution: %sx%s Proxy: %sx%s """ % (os.environ['IC_JOB'], os.environ['IC_SHOT'], os.environ['IC_USERNAME'], os.environ['IC_LINEAR_UNIT'], os.environ['IC_ANGULAR_UNIT'], os.environ['IC_TIME_UNIT'], os.environ['IC_STARTFRAME'], os.environ['IC_ENDFRAME'], os.environ['IC_FPS'], os.environ['IC_RESOLUTION_X'], os.environ['IC_RESOLUTION_Y'], os.environ['IC_PROXY_RESOLUTION_X'], os.environ['IC_PROXY_RESOLUTION_Y']) dialog.display(message, title, conf=True)
def clearRecentFiles(self): """ Clear all recent files. """ dialog = prompt.dialog() message = "About to delete all recent files information. Are you sure?" if dialog.display(message, "Confirm"): success, msg = os_wrapper.remove(os.environ['IC_RECENTFILESDIR']) if not success: dialog.display(msg, "Error", conf=True)
def createShots(self): """ Create the shot(s). """ success = 0 existing = 0 failure = 0 shots_created = "" shots_existing = "" shots_failed = "" dialog_msg = "" for shot in self.shots_to_create: shot_datafile = self.getShotDatafile(shot) os_wrapper.createDir(os.path.dirname(shot_datafile)) if self.shot_data.load(shot_datafile): existing += 1 shots_existing += shot + "\n" elif self.shot_data.save(): success += 1 shots_created += shot + "\n" else: failure += 1 shots_failed += shot + "\n" if success: message = "%d %s created successfully: " % ( success, verbose.pluralise('shot', success)) dialog_msg += "%s\n%s\n" % (message, shots_created) verbose.message(message + shots_created) if existing: message = "The following %d shot(s) were not created as they already exist: " % existing dialog_msg += "%s\n%s\n" % (message, shots_existing) verbose.warning(message + shots_existing) if failure: message = "The following %d shot(s) could not be created - please check write permissions and try again: " % failure dialog_msg += "%s\n%s\n" % (message, shots_failed) verbose.error(message + shots_failed) # Confirmation dialog dialog_title = "Shot Creator Results" dialog = prompt.dialog() dialog.display(dialog_msg, dialog_title, conf=True) self.populateShots()
def addJob(self): """ Open the edit job dialog to add a new job. """ editJobDialog = edit_job.dialog(parent=self) if editJobDialog.display('', '$IC_JOBSROOT', os.environ['IC_VERSION'], True): if self.j.addJob(editJobDialog.jobName, editJobDialog.jobPath, editJobDialog.jobVersion, editJobDialog.jobActive): self.reloadJobs(reloadDatabase=False, selectItem=editJobDialog.jobName) else: errorMsg = "Could not create job as a job with the name '%s' already exists." % editJobDialog.jobName dialogMsg = errorMsg + "\nWould you like to create a job with a different name?" verbose.error(errorMsg) # Confirmation dialog dialogTitle = 'Job Not Created' dialog = prompt.dialog() if dialog.display(dialogMsg, dialogTitle): self.addJob()
def checkRootPaths(self): """ Check if root paths have been set, and if not prompt the user to set them up. """ self.j.getRootPaths() if (self.j.win_root is None) or (self.j.osx_root is None) or (self.j.linux_root is None): dialogMsg = "Paths to the root of the shared filesystem must be set for each OS to enable cross-platform portability. Please set the values in the next dialog." #verbose.print_(dialogMsg, 1) verbose.warning("Root filesystem path(s) not set.") # Confirmation dialog dialogTitle = "Root Paths Not Set" dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True) self.editPaths()
def file_save_native_dialog(self, starting_dir=None): """ Display a native dialog for saving a file. N.B. try/except to catch RuntimeError when dialog is cancelled. """ try: if starting_dir is None: nuke.scriptSaveAs() else: nuke.scriptSaveAs(os.path.join(starting_dir, '.')) return True except RuntimeError as e: if str(e) != "Cancelled": dialog = prompt.dialog() dialog.display(str(e), "Error Saving File", conf=True) return False
def deleteShots(self): """ Delete the selected shot(s). TODO: implement properly """ # Confirmation dialog dialog_title = "Delete shot: %s" % self.shot dialog_msg = "Are you sure?" dialog = prompt.dialog() if dialog.display(dialog_msg, dialog_title): shot_path = os_wrapper.absolutePath("%s/$IC_SHOTSDIR/%s" % (self.job_path, self.shot)) result, msg = os_wrapper.remove(shot_path) if result: verbose.message("Shot '%s' deleted: %s" % (self.shot, self.job_path)) self.populateShots() else: dialog.display(msg, "Failed to delete shot", conf=True)
def browseDir(self): """ Open a dialog from which to select a folder. """ startingDir = os_wrapper.translatePath(self.ui.jobPath_lineEdit.text()) if os.path.isdir(startingDir): dialogHome = startingDir else: dialogHome = os.environ['IC_JOBSROOT'] # Append slash to path if it's a Windows drive letter, otherwise file # dialog won't open the correct location if dialogHome.endswith(':'): dialogHome += '/' #dialogPath = QtWidgets.QFileDialog.getExistingDirectory(self, self.tr('Directory'), dialogHome, QtWidgets.QFileDialog.DontResolveSymlinks | QtWidgets.QFileDialog.ShowDirsOnly) ##dialog = QtWidgets.QFileDialog(self) dialogPath = self.folderDialog(dialogHome) if dialogPath: # if dialog.exec_(): # dialogPath = dialog.getExistingDirectory(self, self.tr('Directory'), dialogHome, QtWidgets.QFileDialog.DontResolveSymlinks | QtWidgets.QFileDialog.ShowDirsOnly) if os_wrapper.checkIllegalChars(dialogPath): #, r'[^\w\.-]'): jobPath = os_wrapper.relativePath(dialogPath, 'IC_JOBSROOT') self.ui.jobPath_lineEdit.setText(jobPath) # Only autofill job name field it it's empty if not self.ui.jobName_lineEdit.text(): try: # if os.environ['IC_JOBSROOT'] in os_wrapper.absolutePath(jobPath): # jobName = jobPath.split('/')[1] # else: # jobName = jobPath.split('/')[-1] jobName = os.path.basename(jobPath) self.ui.jobName_lineEdit.setText(jobName) except IndexError: pass else: verbose.illegalCharacters(dialogPath) # Warning dialog dialogTitle = "Path contains illegal characters" dialogMsg = "The path \"%s\" contains illegal characters. File and folder names must be formed of alphanumeric characters, underscores, hyphens and dots only." % dialogPath dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def file_save_as(self, filepath): """ Save the current file to the specified filepath. If the destination dir doesn't exist, create it. Nuke automatically prompts if file already exists. N.B. try/except to catch RuntimeError when dialog is cancelled. """ try: dirname = os.path.dirname(filepath) if not os.path.isdir(dirname): os_wrapper.createDir(dirname) nuke.scriptSaveAs(filepath) recent_files.recents.put(filepath) self.update_recents_menu() return filepath except RuntimeError as e: if str(e) != "Cancelled": dialog = prompt.dialog() dialog.display(str(e), "Error Saving File", conf=True) return False
def file_open(self, filepath): """ Open the specified file. """ if self.confirm(): try: nuke.scriptClear() nuke.scriptOpen(filepath) recent_files.recents.put(filepath) self.update_recents_menu() return filepath except RuntimeError as e: # exc_type, exc_value, exc_traceback = sys.exc_info() # # traceback.print_exception(exc_type, exc_value, exc_traceback) # dialog_msg = traceback.format_exception_only(exc_type, exc_value)[0] dialog = prompt.dialog() dialog.display(str(e), "Error Opening File", conf=True) return False else: return False
def editJob(self): """ Open edit job dialog. """ item = self.ui.jobs_listWidget.selectedItems()[0] jobName = item.text() editJobDialog = edit_job.dialog(parent=self) if editJobDialog.display(jobName, self.j.getPath(jobName), self.j.getVersion(jobName), self.j.getEnabled(jobName)): self.j.enableJob(jobName, editJobDialog.jobActive) self.j.setVersion(jobName, editJobDialog.jobVersion) self.j.setPath(jobName, editJobDialog.jobPath) if self.j.renameJob(jobName, editJobDialog.jobName): # Do this last as jobs are referenced by name self.reloadJobs(reloadDatabase=False, selectItem=editJobDialog.jobName) else: errorMsg = "Could not rename job as a job with the name '%s' already exists." % editJobDialog.jobName dialogMsg = errorMsg + "\nWould you still like to edit the job '%s'?" % jobName verbose.error(errorMsg) # Confirmation dialog dialogTitle = 'Job Not Created' dialog = prompt.dialog() if dialog.display(dialogMsg, dialogTitle): self.editJob()
def file_save_as(self, filepath): """ Save the current file to the specified filepath. If the destination dir doesn't exist, Houdini will automatically create it. """ # Remove backslashes from path as this causes issues on Windows... filepath = os_wrapper.absolutePath(filepath) # print("Saving: %s" % filepath) # Hide UI to prevent is stealing focus from Houdini's own dialog... self.file_save_ui.hide() try: hou.hipFile.save(filepath) self.set_hip_and_job_vars( set_hip_explicit=os.path.dirname(filepath)) recent_files.recents.put(filepath) return filepath except hou.OperationFailed as e: dialog = prompt.dialog() dialog.display(str(e), "Error Saving File", conf=True) return False
def publish(pblTo, slShot, subtype, pblNotes): # Get selection nodeLs = nuke.root().nodes() # Define main variables shot_ = '' assetType = 'nk_%s' % subtype subsetName = '' prefix = '' convention = subtype suffix = '' fileType='nk' extension = 'nk' # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % (assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = nuke.root().name() #nukeOps.getScriptName() icPblData.writeData(pblDir, assetPblName, assetPblName, assetType, extension, version, pblNotes, src) # Nuke operations icSet = nukeOps.createBackdrop(assetPblName, nodeLs) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) # nukeOps.saveAs(pathToPblAsset) nuke.scriptSaveAs(pathToPblAsset) nuke.delete(icSet) # Take snapshot nukeOps.viewerSnapshot(pblDir) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % (assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(dailyPblOpts, pblTo, pblNotes): dailySeq, dailyRange, dailyType, dailyPath = dailyPblOpts #nameBody, extension = os.path.splitext(dailySeq) #extension = extension[1:] # remove leading dot from file extension nameBody, padding_, extension = dailySeq.rsplit('.', 2) padding = len(padding_) job = os.environ['IC_JOB'] assetType = 'dailies' prefix = '' convention = '' suffix = '' subsetName = dailyType assetExt = '' assetPblName = '%s%s%s' % (prefix, convention, suffix) assetName = assetPblName shotSaneName = os.environ['IC_SHOT'].replace('/', '_') # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) renderRootPblDir = pblDir # Version control currentVersion = vCtrl.version(pblDir, current=True) version = vCtrl.version(pblDir) # Confirmation dialog dialogMsg = '' dialogTitle = 'Publishing' dialogMsg += 'Name:\t%s_%s\n\nVersion:\t%s\n\nNotes:\t%s' % (shotSaneName, subsetName, version, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return try: verbose.pblFeed(begin=True) pblResult = 'SUCCESS' # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # File operations dailyPath = os.path.expandvars(dailyPath) try: startFrame, endFrame = dailyRange.split('-') except ValueError: startFrame = endFrame = dailyRange # if frame range is a single frame try: posterFrame_ = int(os.environ['IC_POSTER_FRAME']) except ValueError: posterFrame_ = -1 if not (int(startFrame) <= posterFrame_ <= int(endFrame)): # if poster frame is not within frame range, use mid frame posterFrame_ = (int(startFrame)+int(endFrame)) / 2 posterFrame = str(posterFrame_).zfill(padding) # Pass arguments to djv to process the files in djvOps dailyFileBody = '%s_dailies_%s' % (shotSaneName, subsetName) dailyFile = '%s.%s.jpg' % (dailyFileBody, startFrame) inFile = os.path.join(dailyPath, nameBody) #print(inFile) outFile = os.path.join(pblDir, dailyFileBody) #djvOps.prcImg(inFile, outFile, startFrame, endFrame, extension, outExt='jpg', fps=os.environ['IC_FPS']) djvOps.prcQt(inFile, pblDir, startFrame, endFrame, extension, name='%s_%s' % (dailyFileBody, version)) # Hard linking daily to dated folder in wips dir dailyFileLs = os.listdir(pblDir) dailyDateDir = time.strftime('%Y_%m_%d') dailyDatePath = os.path.join(os.environ['IC_WIPS_DIR'], 'CGI', dailyDateDir, '%s_%s_%s' % (shotSaneName, subsetName, version)) os_wrapper.createDir(dailyDatePath) excludeLs = ['in_progress.tmp'] for file_ in dailyFileLs: if file_ not in excludeLs: os_wrapper.hardLink(os.path.join(pblDir, file_), os.path.join(dailyDatePath, file_)) dailyFile = file_ # Create daily snapshot previewoutFile = os.path.join(pblDir, 'preview') djvOps.prcImg(inFile, previewoutFile, posterFrame, posterFrame, extension, resize=(512,288), outExt='jpg') #djvOps.prcQt(inFile, pblDir, startFrame, endFrame, extension, resize=(512,288)) # Store asset metadata in file assetPblName += '_%s' % version #src = renderDic['main'] src = dailySeq icPblData.writeData(pblDir, assetPblName, assetName, assetType, assetExt, version, pblNotes, src) # Delete in-progress tmp file inProgress.end(pblDir) inProgress.end(dailyDatePath) # Published asset check pblDirResult = pblChk.success(os.path.join(pblDir, dailyFile)) dailyDirResult = pblChk.success(os.path.join(dailyDatePath, dailyFile)) print(os.path.join(pblDir, dailyFile)) print(os.path.join(dailyDatePath, dailyFile)) pblResult = 'SUCCESS' if pblDirResult != pblResult or dailyDirResult != pblResult: pblResult = 'FAILED' raise Exception(verbose.dailyFail()) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) os_wrapper.remove(dailyDatePath) pblResult = pblChk.success(pathToPblAsset) pblResult += " - " + verbose.pblRollback() # Show publish result dialog dialogTitle = "Publish Report" dialogMsg = "Render:\t%s\n\nVersion:\t%s\n\n%s" % (assetPblName, version, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, subtype, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables shot_ = os.environ['IC_SHOT'] assetType = 'ic_camera' subsetName = '' prefix = '' convention = subtype suffix = '_camera' fileType = 'mayaAscii' extension = 'ma' # Get all dependents allObjLs = mc.listRelatives(objLs[0], ad=True, f=True, typ='transform') if allObjLs: allObjLs.append(objLs[0]) else: allObjLs = [objLs[0]] # Check if selection is a camera if not mayaOps.cameraNodeCheck(objLs[0]): verbose.notCamera() return # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % assetPblName # convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % ( assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() # icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) icPblData.writeData(pblDir, assetPblName, assetPblName, assetType, extension, version, pblNotes, src) # Maya operations mayaOps.deleteICDataSet(allObjLs) newcamLs = mayaOps.cameraBake(objLs, assetPblName) objLs = [newcamLs[0]] attrLs = [ '.tx', '.ty', '.tz', '.rx', '.ry', '.rz', '.sx', '.sy', '.sz' ] mayaOps.lockAttr(objLs, attrLs) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportSelection(pathToPblAsset, fileType) mayaOps.nkCameraExport(objLs, pblDir, assetPblName, version) mayaOps.exportGeo(objLs, 'fbx', pathToPblAsset) # os_wrapper.setPermissions(os.path.join(pblDir, '*')) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % ( assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables shot_ = os.environ['IC_SHOT'] assetType = 'ma_anim' subsetName = '' prefix = '' convention = objLs[0] suffix = '_anim' fileType = 'atomExport' extension = 'atom' # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Get all dependents allObjLs = mc.listRelatives(convention, ad=True, f=True) # Add original selection to allObj if no dependents are found if allObjLs: allObjLs.append(convention) else: allObjLs = [convention] # Check if asset to publish is a set if mc.nodeType(convention) == 'objectSet': verbose.noSetsPbl() return # Check if asset to publish is an icSet if mayaOps.chkIcDataSet(convention): verbose.noICSetsPbl() return # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Check if selected asset is a published asset and matches the asset name try: ICSetConn = mc.listConnections('%s.icARefTag' % convention) if not ICSetConn[0].startswith('ICSet'): raise RuntimeError('ICSet') except: verbose.pblAssetReq() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % ( assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() requires = mc.getAttr('%s.icRefTag' % ICSetConn[0]) compatible = '%s_%s' % (requires, mc.getAttr('ICSet_%s.icVersion' % requires)) icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src, requires, compatible) # Maya operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportAnimation(pathToPblAsset, pblDir, objLs) # os_wrapper.setPermissions(os.path.join(pblDir, '*')) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % ( assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def gather(gatherPath): gatherPath = os.path.expandvars(gatherPath) # Instantiate data classes assetData = metadata.Metadata(os.path.join(gatherPath, 'asset_data.json')) try: assetPblName = assetData.get_attr('asset', 'assetPblName') asset = assetData.get_attr('asset', 'asset') assetType = assetData.get_attr('asset', 'assetType') assetExt = assetData.get_attr('asset', 'assetExt') # Check for preferred .ma or .mb extension for item_ in os.listdir(gatherPath): if item_.endswith('.ma'): assetExt = 'ma' elif item_.endswith('.mb'): assetExt = 'mb' # Get published asset from the gatherPath assetPath = os.path.join(gatherPath, '%s.%s' % (assetPblName, assetExt)) if not os.path.isfile(assetPath): verbose.noAsset() return False # Load the appropriate plugin if needed if assetExt == 'abc': mc.loadPlugin('AbcImport', qt=True) elif assetExt == 'fbx': mc.loadPlugin('fbxmaya', qt=True) elif assetExt == 'obj': mc.loadPlugin('objExport', qt=True) # Gathering... drawOverrides = True if assetType == 'ma_shot': mayaOps.openScene(assetPath, dialog=False, updateRecentFiles=False) mayaOps.redirectScene( os.path.join(os.environ['IC_MAYA_SCENES_DIR'], 'untitled')) return False elif assetExt == 'vrmesh': chkNameConflict(asset) mel.eval( 'vrayCreateProxy -node "%s" -dir "%s" -existing -createProxyNode;' % (asset, assetPath)) vrmeshSG = mc.listSets(ets=True, t=1, object=asset)[0] vrmeshShd = mc.listConnections('%s.surfaceShader' % vrmeshSG, s=True, d=False)[0] mc.delete(vrmeshSG) mc.delete(vrmeshShd) newNodeLs = [asset] elif assetExt == 'abc': chkNameConflict(asset) newNodeLs = mc.file(assetPath, i=True, iv=True, rnn=True) else: chkNameConflict(asset) newNodeLs = mc.file(assetPath, i=True, iv=True, rnn=True) # Bypasses maya not displaying shading groups in sets. Adds the material node to icSet instead. Sets draw overrides to False. if assetType == 'ma_shader': drawOverrides = False connLs = mc.listConnections(asset, p=True) for conn in connLs: if '.outColor' in conn: icSetAsset = conn.split('.')[0] else: icSetAsset = asset # Sets draw overrides to false if asset is node if assetType == 'ma_node' or assetType == 'ic_node': drawOverrides = False # Generate icSet chkNameConflict('ICSet_%s' % assetPblName) # Connect original to icSet if assetType != 'ma_scene': dataSet = mayaOps.icDataSet(icSetAsset, assetData, update=None, drawOverrides=drawOverrides, addElements=True) mc.select(asset, r=True, ne=True) mc.addAttr(ln='icARefTag', dt='string') mc.connectAttr('%s.icRefTag' % dataSet, '%s.icARefTag' % asset, f=True) mayaOps.lockAttr([asset], ['.icARefTag'], children=False) else: drawOverrides = False mayaOps.icDataSet(icSetAsset, assetData, update=None, drawOverrides=drawOverrides, addElements=False) return True except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) dialogTitle = 'Gather Warning' dialogMsg = 'Errors occured during asset update.\nPlease check console for more information.\n\n%s' % traceback.format_exc( ) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True) return False
def gather(gatherPath): gatherPath = os.path.expandvars(gatherPath) # Instantiate data classes assetData = metadata.Metadata(os.path.join(gatherPath, 'asset_data.json')) assetPblName = assetData.get_attr('asset', 'assetPblName') assetType = assetData.get_attr('asset', 'assetType') assetExt = assetData.get_attr('asset', 'assetExt') version = assetData.get_attr('asset', 'version') notes = assetData.get_attr('asset', 'notes') # Check if objects with same name exist in script icSetName = 'ICSet_%s_%s' % (assetPblName, version) nukeOps.resolveNameConflict(icSetName) # Check for preferred .nk extension for item_ in os.listdir(gatherPath): if item_.endswith('.nk'): assetExt = 'nk' try: # Get published asset from the gatherPath gatherPath += '/%s.%s' % (assetPblName, assetExt) if not os.path.isfile(gatherPath): verbose.noAsset() return # Gathering... nuke.nodePaste(gatherPath) # Add ICSet custom attributes tileRGB = 0.316 fontRGB = 0.65 tileHex = int( '%02x%02x%02x%02x' % (tileRGB * 255, tileRGB * 255, tileRGB * 255, 1), 16) fontHex = int( '%02x%02x%02x%02x' % (fontRGB * 255, fontRGB * 255, fontRGB * 255, 1), 16) icarusIcon = '<center><img src=icarus.png>' icSet = nuke.toNode(assetPblName) notesTab = nuke.Tab_Knob('icNotes', 'Icarus Notes') notesKnob = nuke.Multiline_Eval_String_Knob('notes', 'Notes') icSet.addKnob(notesTab) icSet.addKnob(notesKnob) icSet['notes'].setValue(notes) icSet['name'].setValue(icSetName) icSet['label'].setValue('%s\n%s' % (icarusIcon, assetType)) icSet['note_font_size'].setValue(15) icSet['tile_color'].setValue(tileHex) icSet['note_font_color'].setValue(fontHex) # Lock attributes icSet['notes'].setEnabled(False) icSet['label'].setEnabled(False) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) dialogTitle = 'Gather Warning' dialogMsg = 'Errors occured during asset update.\nPlease check console for more information.\n\n%s' % traceback.format_exc( ) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def gather(gatherPath): gatherPath = os.path.expandvars(gatherPath) # Instantiate data classes assetData = metadata.Metadata(os.path.join(gatherPath, 'asset_data.json')) assetPblName = assetData.get_attr('asset', 'assetPblName') assetType = assetData.get_attr('asset', 'assetType') assetExt = assetData.get_attr('asset', 'assetExt') version = assetData.get_attr('asset', 'version') notes = assetData.get_attr('asset', 'notes') # Retrieve trsData from gatherPath. I've left this here for compatibility, ultimately need to look into rewriting this. sys.path.append(gatherPath) if assetType == 'ic_pointCloud': import trsData reload(trsData) sys.path.remove(gatherPath) # Check if objects with same name exist in script icSetName = 'ICSet_%s_%s' % (assetPblName, version) nukeOps.resolveNameConflict(icSetName) try: # Get published asset from the gatherPath assetPath = os.path.join(gatherPath, '%s.%s' % (assetPblName, assetExt)) if not os.path.isfile(assetPath): verbose.noAsset() return # Deselect all nodes selNodes = nuke.selectedNodes() for selNode in selNodes: selNode['selected'].setValue(False) # Create readGeo icSet = nuke.createNode('ReadGeo2', 'file {%s}' % assetPath) # Make all items in geo hierarchy visible in scene view if geo type is alembic if assetExt == 'abc': sceneView = icSet['scene_view'] allItems = sceneView.getAllItems() sceneView.setImportedItems(allItems) sceneView.setSelectedItems(allItems) # Add ICSet custom attributes tileRGB = 0.316 fontRGB = 0.65 tileHex = int( '%02x%02x%02x%02x' % (tileRGB * 255, tileRGB * 255, tileRGB * 255, 1), 16) fontHex = int( '%02x%02x%02x%02x' % (fontRGB * 255, fontRGB * 255, fontRGB * 255, 1), 16) icarusIcon = '<center><img src=icarus.png>\n%s' % assetType notesTab = nuke.Tab_Knob('icNotes', 'Icarus Notes') notesKnob = nuke.Multiline_Eval_String_Knob('notes', 'Notes') icSet.addKnob(notesTab) icSet.addKnob(notesKnob) icSet['notes'].setValue(notes) icSet['name'].setValue(icSetName) icSet['cacheLocal'].setValue(0) icSet['label'].setValue(icarusIcon) icSet['note_font_size'].setValue(15) icSet['tile_color'].setValue(tileHex) icSet['note_font_color'].setValue(fontHex) # Lock attributes icSet['notes'].setEnabled(False) icSet['label'].setEnabled(False) icSet['file'].setEnabled(False) # If geo is pointCloud, apply transformation matrix if assetType == 'ic_pointCloud': icSet['translate'].setValue(trsData.t[0], 0) icSet['translate'].setValue(trsData.t[1], 1) icSet['translate'].setValue(trsData.t[2], 2) icSet['rotate'].setValue(trsData.r[0], 0) icSet['rotate'].setValue(trsData.r[1], 1) icSet['rotate'].setValue(trsData.r[2], 2) icSet['scaling'].setValue(trsData.s[0], 0) icSet['scaling'].setValue(trsData.s[1], 1) icSet['scaling'].setValue(trsData.s[2], 2) icSet['xform_order'].setValue(0) icSet['rot_order'].setValue(0) icSet['display'].setValue(1) # Update message #nuke.message('WARNING: Please update ReadGeo node frame rate to shot settings') except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) dialogTitle = 'Gather Warning' dialogMsg = 'Errors occured during asset update.\nPlease check console for more information.\n\n%s' % traceback.format_exc( ) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, subtype, textures, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables assetType = 'ma_model' subsetName = subtype prefix = '' convention = objLs[0] suffix = '_%s_model' % subtype fileType = 'mayaBinary' extension = 'mb' autoLods = False # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Get all dependents. Creates a group for LODs with just dependents allObjLs = mc.listRelatives(convention, ad=True, f=True, typ='transform') objLodLs = allObjLs # Add original selection to allObj if no dependents are found if allObjLs: allObjLs.append(convention) else: allObjLs = [convention] objLodLs = [convention] # Check if asset to publish is a set if mc.nodeType(convention) == 'objectSet': verbose.noSetsPbl() return # Check if asset to publish is an icSet if mayaOps.chkIcDataSet(convention): verbose.noICSetsPbl() return # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % (assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) if textures: os_wrapper.createDir(os.path.join(pblDir, 'tx')) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() #for i in ('pblDir', 'assetPblName', 'convention', 'assetType', 'extension', 'version', 'src', 'pblNotes') # publishVars[i] = locals()[i] #icPblData.writeData(publishVars) icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) # Publish operations mayaOps.deleteICDataSet(allObjLs) if textures: # Copy textures to publish directory (use hardlink instead?) txFullPath = os.path.join(pblDir, 'tx') # txRelPath = txFullPath.replace(os.path.expandvars('$IC_JOBPATH'), '$IC_JOBPATH') # txPaths = (txFullPath, txRelPath) # Returns a dict for fileNodes and oldTxPaths if updateMaya = True oldTxPaths = mayaOps.updateTextures(txFullPath, txObjLs=allObjLs, updateMaya=True) # Take snapshot mayaOps.snapShot(pblDir, isolate=True, fit=True) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportSelection(pathToPblAsset, fileType) # Reverts the texture paths if textures and oldTxPaths: mayaOps.relinkTextures(oldTxPaths) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) # was commented out? pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % (assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(renderDic, pblTo, mainLayer, streamPbl, pblNotes): job = os.environ['IC_JOB'] assetType = 'render' prefix = '' convention = '' suffix = '' subsetName = os.environ['IC_SHOT'] assetExt = '' assetPblName = '%s%s%s' % (prefix, convention, suffix) assetName = assetPblName # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) renderRootPblDir = pblDir # Version control currentVersion = vCtrl.version(pblDir, current=True) version = vCtrl.version(pblDir) # Checks if no main layer was set and cancels publish if publishing first version if version == 'v001': if not mainLayer: verbose.noMainLayer() return # Confirmation dialog dialogMsg = '' dialogTitle = 'Publishing Render' if not streamPbl: dialogMsg += "Warning:\n\nPublish won't be streamed.\nLayers from previous renders will not be ported.\n\n\n" if not mainLayer: dialogMsg += 'Warning:\n\nNo main layer was set.\nThe main render layer will be ported from the previous publish.\n\nContinue?\n\n\n' dialogMsg += 'Render:\t%s\n\nVersion:\t%s\n\nNotes:\t%s' % ( assetPblName, version, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return try: verbose.pblFeed(begin=True) pblResult = 'SUCCESS' # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # File operations if not mainLayer: streamPbl = True elif version == 'v001': streamPbl = True # Streaming publish. Hard linking previous version and removing previous icarus data files if streamPbl: if version != 'v001': # Get all layers in current publish currentPblLayerLs = os.listdir( os.path.join(renderRootPblDir, currentVersion)) for currentPblLayer in currentPblLayerLs: # Create respective layer folder in new version if os.path.isdir( os.path.join(renderRootPblDir, currentVersion, currentPblLayer)): os_wrapper.createDir( os.path.join(pblDir, currentPblLayer)) # Get all files in current layer currentLayerFileLs = sorted( os.listdir( os.path.join(renderRootPblDir, currentVersion, currentPblLayer))) # Hard linking files to new version for currentLayerFile in currentLayerFileLs: verbose.pblFeed(msg='Processing %s' % currentLayerFile) os_wrapper.hardLink( os.path.join(renderRootPblDir, currentVersion, currentPblLayer, currentLayerFile), os.path.join(pblDir, currentPblLayer)) # Process all new layers and passes for key in renderDic.keys(): srcLayerDir = os.path.expandvars( renderDic[key]) # expand environment variables in render path dirContents = sorted(os.listdir(srcLayerDir)) for file_ in dirContents: verbose.pblFeed(msg='Processing %s' % file_) if key == mainLayer: os_wrapper.createDir(os.path.join(pblDir, 'main')) #if os.path.isfile(os.path.join(srcLayerDir, file_)): # prcFile = pblOptsPrc.renderName_prc(key, 'main', file_) # if prcFile: # os_wrapper.hardLink(os.path.join(srcLayerDir, file_), os.path.join(pblDir, 'main', prcFile)) os_wrapper.hardLink(os.path.join(srcLayerDir, file_), os.path.join(pblDir, key)) else: destLayerDir = os.path.join(pblDir, key) if not os.path.isdir(destLayerDir): os_wrapper.createDir(destLayerDir) os_wrapper.hardLink(os.path.join(srcLayerDir, file_), destLayerDir) # Create publish snapshot from main layer new version mainLayerDir = os.path.join(pblDir, 'main') mainLayerFileLs = sorted(os.listdir(mainLayerDir)) mainLayerPaddingLs = [] snapShot = False #print(mainLayerFileLs) for mainLayerFile in mainLayerFileLs: #if '_main.' in mainLayerFile: if '_main' in mainLayerFile: # use regex for better matching snapShot = True mainLayerBody, mainLayerPadding, mainLayerExtension = pblOptsPrc.render_split( mainLayerFile) mainLayerPaddingLs.append(mainLayerPadding) if snapShot: verbose.pblSaveSnapshot() startFrame = int(min(mainLayerPaddingLs)) endFrame = int(max(mainLayerPaddingLs)) # midFrame = int((int(startFrame) + int(endFrame))/2) try: posterFrame = int(os.environ['IC_POSTER_FRAME']) except ValueError: posterFrame = -1 if not ( startFrame <= posterFrame <= endFrame ): # if poster frame is not within frame range, use mid frame posterFrame = int((startFrame + endFrame) / 2) inFile = os.path.join(mainLayerDir, mainLayerBody) outFile = os.path.join(pblDir, 'preview') djvOps.prcImg(inFile, outFile, posterFrame, posterFrame, mainLayerExtension[1:], resize=(512, 288), outExt='jpg') #djvOps.prcQt(inFile, pblDir, startFrame, endFrame, mainLayerExtension, resize=(256,144)) # Store asset metadata in file assetPblName += '_%s' % version # src = renderDic['main'] src = None icPblData.writeData(pblDir, assetPblName, assetName, assetType, assetExt, version, pblNotes, src) # Delete in-progress tmp file inProgress.end(pblDir) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = "Publish Report" dialogMsg = "Render:\t%s\n\nVersion:\t%s\n\n\n%s" % (assetPblName, version, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, subtype, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables assetType = 'ma_geoCache' subsetName = subtype prefix = '' convention = objLs[0] suffix = '_%s_geoCache' % subtype if subtype == 'vrmesh': fileType = 'vrmesh' extension = 'vrmesh' elif subtype == 'realflow': fileType = 'sd' extension = 'sd' else: fileType = 'abc' extension = 'abc' # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Get all dependents allObjLs = mc.listRelatives(convention, ad=True, f=True, typ='transform') if allObjLs: allObjLs.append(convention) else: allObjLs = [convention] # Check if asset to publish is a set if mc.nodeType(convention) == 'objectSet': verbose.noSetsPbl() return # Check if asset to publish is an icSet if mayaOps.chkIcDataSet(convention): verbose.noICSetsPbl() return # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % (assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) # Maya operations mayaOps.deleteICDataSet(allObjLs) # Take snapshot mayaOps.snapShot(pblDir, isolate=True, fit=True) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportGeo(objLs, fileType, pathToPblAsset) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % (assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, scnName, subtype, textures, pblNotes): # Define main variables assetType = 'ma_scene' subsetName = subtype prefix = '' convention = scnName suffix = '_scene' fileType = 'mayaAscii' extension = 'ma' # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Get all dependents allObjLs = mc.ls(tr=True) # Remove Maya's default cameras from list defaultCamLs = ['front', 'persp', 'side', 'top'] for defaultCam in defaultCamLs: allObjLs.remove(defaultCam) # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % (assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) if textures: os_wrapper.createDir(os.path.join(pblDir, 'tx')) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) # Publish operations try: mc.select('ICSet_*', ne=True, r=True) icSetLs = mc.ls(sl=True) for icSet in icSetLs: mc.delete(icSet) except: pass if textures: # Copy textures to publish directory (use hardlink instead?) txFullPath = os.path.join(pblDir, 'tx') # txRelPath = txFullPath.replace(os.path.expandvars('$IC_JOBPATH'), '$IC_JOBPATH') # txPaths = (txFullPath, txRelPath) # Returns a dict for fileNodes and oldTxPaths if updateMaya = True oldTxPaths = mayaOps.updateTextures(txFullPath, updateMaya=True) # Take snapshot mayaOps.snapShot(pblDir, isolate=False, fit=False) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) activeScene = mayaOps.getScene() mayaOps.redirectScene(pathToPblAsset) mayaOps.saveFile(fileType, updateRecentFiles=False) # Reverts the texture paths if textures and oldTxPaths: mayaOps.relinkTextures(oldTxPaths) mayaOps.redirectScene(activeScene) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % (assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, subtype, textures, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables geoType = 'abc' subsetName = subtype assetType = 'ic_pointCloud' prefix = '' convention = objLs[0] suffix = '_pointCloud' ma_fileType = 'mayaBinary' extension = geoType # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Check if item is particle objSh = mc.listRelatives(objLs[0])[0] objType = mayaOps.nodetypeCheck(objSh) if objType not in ('particle', 'nParticle'): verbose.pointCloudParticle() return # Get all dependents allObjLs = mc.listRelatives(convention, ad=True, f=True, typ='transform') if allObjLs: allObjLs.append(convention) else: allObjLs = [convention] # Check if asset to publish is a set if mc.nodeType(convention) == 'objectSet': verbose.noSetsPbl() return # Check if asset to publish is an icSet if mayaOps.chkIcDataSet(convention): verbose.noICSetsPbl() return # Check if asset to publish is referenced for allObj in allObjLs: if mc.referenceQuery(allObj, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot pblRelDir = '$IC_SHOTPUBLISHDIR' else: pblRelDir = '$IC_JOBPUBLISHDIR' # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % ( assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) if textures: os_wrapper.createDir(os.path.join(pblDir, 'tx')) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) # Maya operations if textures: # Copy textures to publish directory (use hardlink instead?) txFullPath = os.path.join(pblDir, 'tx') # txRelPath = txFullPath.replace(pblTo, pblRelDir) # txPaths = (txFullPath, txRelPath) # Returns a dict for fileNodes and oldTxPaths if updateMaya = True oldTxPaths = mayaOps.updateTextures(txFullPath, txObjLs=allObjLs, updateMaya=True) # Get transform data, write to file and zero obj out objTrs = mayaOps.getTransforms(convention) if objTrs: objT, objR, objS = objTrs else: raise RuntimeError(verbose.noGetTranforms()) trsDataFile = open('%s/trsData.py' % (pblDir), 'w') trsDataFile.write('t=%s\nr=%s\ns=%s' % (objT, objR, objS)) trsDataFile.close() mayaOps.applyTransforms(convention, [0, 0, 0], [0, 0, 0], [1, 1, 1]) # Take snapshot mayaOps.snapShot(pblDir, isolate=True, fit=True) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportSelection(pathToPblAsset, ma_fileType) mayaOps.exportGeo(objLs, geoType, pathToPblAsset) # Re-apply original transforms to object mayaOps.applyTransforms(convention, objT, objR, objS) # Reverts the texture paths if textures and oldTxPaths: mayaOps.relinkTextures(oldTxPaths) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % ( assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, slShot, nodeType, textures, pblNotes): # Get selection objLs = mc.ls(sl=True) # Check item count if not pblChk.itemCount(objLs): return # Define main variables assetType = '%s_node' % nodeType subsetName = mc.nodeType(objLs[0]) prefix = '' convention = objLs[0] suffix = '_node' fileType = 'mayaAscii' extension = 'ma' # Check for illegal characters cleanObj = os_wrapper.sanitize(convention) if cleanObj != convention: verbose.illegalCharacters(convention) return # Check if asset to publish is a set if mc.nodeType(convention) == 'objectSet': verbose.noSetsPbl() return # Check if asset to publish is an icSet if mayaOps.chkIcDataSet(convention): verbose.noICSetsPbl() return # Check if asset to publish is referenced if mc.referenceQuery(convention, inr=True): verbose.noRefPbl() return # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Add shot name to assetPblName if asset is being publish to a shot # Determining publish env var for relative directory if pblTo != os.environ['IC_JOBPUBLISHDIR']: assetPblName += '_%s' % slShot # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % ( assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) if textures: os_wrapper.createDir(os.path.join(pblDir, 'tx')) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() icPblData.writeData(pblDir, assetPblName, convention, assetType, extension, version, pblNotes, src) # Maya operations mayaOps.deleteICDataSet(objLs) if textures: # Copy textures to publish directory (use hardlink instead?) txFullPath = os.path.join(pblDir, 'tx') # txRelPath = txFullPath.replace(os.path.expandvars('$IC_JOBPATH'), '$IC_JOBPATH') # txPaths = (txFullPath, txRelPath) # Returns a dict for fileNodes and oldTxPaths if updateMaya = True oldTxPaths = mayaOps.updateTextures(txFullPath, txObjLs=objLs, updateMaya=True) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) mayaOps.exportSelection(pathToPblAsset, fileType) # Write Nuke file if ic and file node type if nodeType == 'ic': if subsetName == 'file': fileTypeLs = ('.jpg', '.jpeg', '.hdr', '.exr', '.tif', '.tiff', '.tga', '.png') fileLs = os.listdir(os.path.join(pblDir, 'tx')) for file_ in fileLs: if file_.endswith(fileTypeLs, -4): fileName = file_ mayaOps.nkFileNodeExport(objLs, nodeType, fileName, pblDir, pblDir, assetPblName, version) # Reverts the texture paths if textures and oldTxPaths: mayaOps.relinkTextures(oldTxPaths) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % ( assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)
def publish(pblTo, pblNotes): # Define main variables assetType = 'ma_shot' subsetName = '' prefix = '' convention = os.environ['IC_SHOT'] suffix = '_shot' fileType = 'mayaAscii' extension = 'ma' # Process asset publish options assetPblName, assetDir, pblDir = pblOptsPrc.prc(pblTo, subsetName, assetType, prefix, convention, suffix) # Version control version = '%s' % vCtrl.version(pblDir) # if approved: # version += '_apv' # Confirmation dialog dialogTitle = 'Publishing %s' % convention dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\nNotes:\t%s' % (assetPblName, version, subsetName, pblNotes) dialog = prompt.dialog() if not dialog.display(dialogMsg, dialogTitle): return # Publishing try: verbose.pblFeed(begin=True) # Create publish directories pblDir = os_wrapper.createDir(os.path.join(pblDir, version)) os_wrapper.createDir(os.path.join(pblDir, 'tx')) # Create in-progress tmp file inProgress.start(pblDir) # Store asset metadata in file src = mayaOps.getScene() icPblData.writeData(pblDir, assetPblName, assetPblName, assetType, extension, version, pblNotes, src) # Publish operations # Copy textures to publish directory (use hardlink instead?) txFullPath = os.path.join(pblDir, 'tx') # txRelPath = txFullPath.replace(os.path.expandvars('$IC_JOBPATH'), '$IC_JOBPATH') # txPaths = (txFullPath, txRelPath) # Returns a dict for fileNodes and oldTxPaths if updateMaya = True oldTxPaths = mayaOps.updateTextures(txFullPath, updateMaya=True) # Take snapshot mayaOps.snapShot(pblDir, isolate=False, fit=False) # File operations pathToPblAsset = os.path.join(pblDir, '%s.%s' % (assetPblName, extension)) verbose.pblFeed(msg=assetPblName) activeScene = mayaOps.getScene() mayaOps.redirectScene(pathToPblAsset) mayaOps.saveFile(fileType, updateRecentFiles=False) # Reverts the texture paths if oldTxPaths: mayaOps.relinkTextures(oldTxPaths) mayaOps.redirectScene(activeScene) # Delete in-progress tmp file inProgress.end(pblDir) # Published asset check pblResult = pblChk.success(pathToPblAsset) verbose.pblFeed(end=True) except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) pathToPblAsset = '' os_wrapper.remove(pblDir) pblResult = pblChk.success(pathToPblAsset) pblResult += verbose.pblRollback() # Show publish result dialog dialogTitle = 'Publish Report' dialogMsg = 'Asset:\t%s\n\nVersion:\t%s\n\nSubset:\t%s\n\n\n%s' % (assetPblName, version, subsetName, pblResult) dialog = prompt.dialog() dialog.display(dialogMsg, dialogTitle, conf=True)