Esempio n. 1
0
 def get_workspace(self):
     self.WorkSpace_RootDir = pm.workspace(q=1,rd=1)
     logging.debug('self.WorkSpace_RootDir:\t%s',self.WorkSpace_RootDir)
     self.RuleEntry_SourceImages = pm.workspace('sourceImages',fileRuleEntry=1,q=1 )
     logging.debug('self.RuleEntry_SourceImages:\t%s',self.RuleEntry_SourceImages)
     self.RuleEntry_3dPaintTextures = pm.workspace('3dPaintTextures',fileRuleEntry=1,q=1 )
     self.RuleEntry_Scenes = pm.workspace('scene',fileRuleEntry=1,q=1 )
     logging.debug('self.RuleEntry_Scenes:\t%s',self.RuleEntry_Scenes)
Esempio n. 2
0
 def get_workspace(self):
     #self.WorkSpace_RootDir = pm.workspace(q=1,rd=1)
     self.RuleEntry_SourceImages = pm.workspace('sourceImages',fileRuleEntry=1,q=1 )
     if not self.RuleEntry_SourceImages :
         self.RuleEntry_SourceImages = 'sourceimages'
     self.RuleEntry_Scenes = pm.workspace('scenes',fileRuleEntry=1,q=1 )
     if not self.RuleEntry_Scenes :
         self.RuleEntry_Scenes = 'scenes'
Esempio n. 3
0
 def set_diskCache_rule(self,dirPath=None):
     if not dirPath:
         dirPath = self.DiskCache_Before
     try:
         pm.workspace(fileRule=('diskCache',dirPath) )
     except:
         traceback.print_exc()
     else:
         try:
             pm.workspace(saveWorkspace=True)
         except:
             traceback.print_exc()
Esempio n. 4
0
    def load_file(self):

        item_path = self.get_item_datas()["PATH"]
        f_path, f_name, f_ext = FileDir_Management.pathSplit(item_path)

        pmc.newFile(force=True)
        pmc.system.openFile(item_path, force=True)

        pmc.workspace(f_path, o=True)
        pmc.workspace(dir=f_path)

        print "#\tFILE PATH --> %s" % item_path
Esempio n. 5
0
 def get_diskCache_rule(self):
     try:
         #workspace -q -fileRuleEntry "diskCache"
         # get file rule entry
         self.DiskCache_Before = pm.workspace('diskCache',fileRuleEntry=1,q=1 )
     except:
         traceback.print_exc()
 def press_vdb_path(param_name):
     basic_filter = "OpenVDB File(*.vdb)"
     project_dir = pm.workspace(query=True, directory=True)
     vdb_path = pm.fileDialog2(fileFilter=basic_filter, cap="Select OpenVDB File", okc="Load", fm=1, startingDirectory=project_dir)
     if vdb_path is not None and len(vdb_path) > 0:
         vdb_path = vdb_path[0]
         # inspect file and try to figure out the padding and such
         try:
             dirname, filename = os.path.split(vdb_path)
             if re.match(".*[\._][0-9]+[\._]vdb", filename):
                 m = re.findall("[0-9]+", filename)
                 frame_number = m[-1]
                 padding = len(frame_number)
                 cache_start = int(frame_number)
                 cache_end = int(frame_number)
                 frame_location = filename.rfind(frame_number)
                 check_file_re = re.compile((filename[:frame_location] + "[0-9]{%i}" % padding + filename[frame_location + padding:]).replace(".", "\\."))
                 for each in os.listdir(dirname):
                     if os.path.isfile(os.path.join(dirname, each)):
                         if check_file_re.match(each):
                             current_frame_number = int(each[frame_location : frame_location + padding])
                             cache_start = min(cache_start, current_frame_number)
                             cache_end = max(cache_end, current_frame_number)
                 frame_location = vdb_path.rfind(frame_number)
                 vdb_path = vdb_path[:frame_location] + "#" * padding + vdb_path[frame_location + padding:]
                 node_name = param_name.split(".")[0]
                 pm.setAttr("%s.cache_playback_start" % node_name, cache_start)
                 pm.setAttr("%s.cache_playback_end" % node_name, cache_end)
         except:
             print "[openvdb] Error while trying to figure out padding, and frame range!"
             import sys, traceback
             traceback.print_exc(file=sys.stdout)
         pm.textFieldButtonGrp("OpenVDBPathGrp", edit=True, text=vdb_path)
         pm.setAttr(param_name, vdb_path, type="string")
Esempio n. 7
0
def constraint_store():
	filepath = os.path.basename( cmds.file(q=True, sn=True) )
	constraints_folder = os.path.join( pm.workspace( q=True, rd=True ), 'data/constraints/')
	if not os.path.exists(os.path.dirname(constraints_folder)):
		os.makedirs(os.path.dirname(constraints_folder))
	sel = pm.ls(sl=True)
	constraintFile=None
	if len(sel)==0:
		pm.error('Select something numbnuts!')
	for obj in sel:
		for child in obj.getChildren():
			type = pm.objectType(child)
			constraintString = None
			if 'Constraint' in type:
				constrainer = child.getWeightAliasList()[0].split('.')[1][:-2]
				#print 'Constraint found of type = %s on object: %s from object: %s' % (type, obj, constrainer)
				#print child.connections(p=True,c=True,d=True)
				if constraintString == None:
					constraintString = type+':'+constrainer+':'+obj
				else:
					constraintString = constraintString + ',' + type+':'+constrainer+':'+obj
				#print constraintString
			if constraintString:
				if constraintFile:
					constraintFile=constraintFile+'\n'+constraintString
				else:
					constraintFile=constraintString
	constraints_file = os.path.join(constraints_folder, gp.getuser(), (filepath[:-3]+'_'+time.strftime("%Y%m%dT%H%M%S")+'.constraints'))
	if not os.path.exists(os.path.dirname(constraints_file)):
		os.makedirs(os.path.dirname(constraints_file))
	with open(constraints_file, 'w') as f:
		f.write(constraintFile)
		print 'Successfully wrote constraints file:\n\t%s' % (constraints_file)
Esempio n. 8
0
 def create_hair_cache(self):
     returnStr = 'create hair cache error'
     # get selection hair shapes
     self.get_sel_hair_shapes()
     
     if self.Hairs :            
         self.get_scene_name()
         if self.Scene_Name :
             # delete cache first
             self.del_cache()
             
             # 
             self.get_diskCache_rule()
             
             # set disk cache file rule
             self.set_diskCache_rule(self.DiskCache_Before + '/' + self.Scene_Name)
             
             # create dir if it not exists
             # else cache can not be write to dir
             dirPath = os.path.join( pm.workspace(q=1,rd=1),\
                                     self.DiskCache_Before,\
                                     self.Scene_Name )
             try:
                 self.create_dir(dirPath)
             except KeyboardInterrupt:
                 print 'user cancel create dir'
                 self.set_diskCache_rule()
                 return returnStr
             except:
                 self.set_diskCache_rule()
                 traceback.print_exc()
                 return returnStr
                     
             # create hair cache
             try:
                 #mel.eval('CreateHairCacheOptions')
                 mel.eval('doHairDiskCache 1 { \"2\", 1, 1, 10, 1 } ')
             except KeyboardInterrupt:
                 print 'user cancel'
                 self.set_diskCache_rule()
                 return returnStr
             except:
                 self.set_diskCache_rule()
                 traceback.print_exc()
                 return returnStr
     
             #save file
             self.save_file()
                 
             # set hair cache name
             self.set_cache_name()
             # re set disk cache file rule to default
             self.set_diskCache_rule()
             
             self.lock_cache_name()
             #save file
             self.save_file()
             
             return 'create hair cache success'
Esempio n. 9
0
    def __init__(self):

        self.working_file_name = pm.env.sceneName()
        self.working_scene_name = os.path.basename(pm.env.sceneName())
        self.working_folder = pm.workspace(fn=True)

        self.sm = pm.ls('sequenceManager1')[0]
        self.sequencer = self.sm.sequences.get()[0]
        self.shot_list = self.sequencer.shots.get()

        self.m_env = mayaEnv.Maya()
Esempio n. 10
0
def camSetup( target_str='', replace_str='' ):
    '''
        camSetup( target_str='_undistort', replace_str='' )
    '''
    filmBacks={'Canon EOS 5D Mark III':[1.41732,0.944882],
               'Canon EOS 5D Mark II':[1.41732,0.944882],
               'Canon EOS-1D Mark IV':[1.41732,0.944882],
               'NIKON D700':[1.41732,0.9409449]}
    cams = [cam for cam in pm.ls(sl=True) if cam.getShape().type() == 'camera' and len(pm.ls(sl=True)) > 0]
    for cam in cams:
        imagePlanes = cam.getShape().listConnections(s=True, d=False, type='imagePlane')
        if imagePlanes:
            image_file = imagePlanes[0].getShape().imageName.get().replace( target_str, replace_str )
            project='/'.join(pm.workspace(q=True,sn=True).split('/')[-3:-1])
            img = PIL.Image.open(image_file)
            exif_data = img._getexif()
            
            if exif_data:
                print 'Exif Data for Cam: %s\'s image plane found from image:\n\t %s' % (cam,image_file)
                if 42036 in exif_data.keys() or 37386 in exif_data.keys():
                    if 37386 in exif_data.keys():
                        focalLength = int(exif_data[37386][0])
                        cam.getShape().focalLength.set(focalLength)
                        print '\tSetting focal length to: %smm' % focalLength
                    elif 42036 in exif_data.keys():
                        focalLength = int(exif_data[42036].split('mm')[0][-2:])
                        cam.getShape().focalLength.set(focalLength)
                        print '\tSetting focal length to: %smm' % focalLength
                    else: print 'No Focal Length Detected'
                if 272 in exif_data.keys():
                    cameraType = exif_data[272]
                    if cameraType in filmBacks.keys():
                        cam.getShape().horizontalFilmAperture.set( filmBacks[cameraType][0] )
                        cam.getShape().verticalFilmAperture.set( filmBacks[cameraType][0] )
                        print '\tFilmBack for Camera type %s set to: %s %s' % (cameraType,
                                                                               filmBacks[cameraType][0],
                                                                               filmBacks[cameraType][1])
                    else:
                        print '\tFilmBack for Camera type %s not in library. Sorry!' % (cameraType)
                else: print 'No Camera Type Detected'
            if image_file:
                #Just in case, removing spaces with bars
                replaceItems = [' ', '/']
                camName = (project+'_projectionCamera_'+os.path.basename(image_file).split('.')[0] + '_CAM')
                for replaceItem in replaceItems:
                    camName.replace(replaceItem,'_')
                cam.rename( camName )
                imagePlanes[0].rename(os.path.basename(image_file))
                imagePlanes[0].depth.set(1000)
                imagePlanes[0].displayOnlyIfCurrent.set(True)
        cam.getShape().displayResolution.set(1)
        cam.getShape().overscan.set(1.2)
        cam.getShape().displayGateMaskColor.set(.1,.1,.1)
        cam.getShape().displayGateMaskOpacity.set(.9)
Esempio n. 11
0
  def openMesh(self, mesh, *args, **kwargs):
    """ export a mesh as obj and open that file in photoshop """
    self.texture = kwargs.get('texture', False)
    
    sel = pm.ls(sl=True)
    path = pm.workspace(q=True,rd=True)
    fileName = 'lcMtPs_temp.obj'
    exportFile = path+fileName
    
    if texture: pm.exportSelected(exportFile, f=2, pr=0, typ='OBJexport', es=1, op="groups=1;ptgroups=1;materials=1;smoothing=1;normals=1")
    else: pm.exportSelected(exportFile, f=2, pr=0, typ='OBJexport', es=1, op="groups=1;ptgroups=1;materials=0;smoothing=1;normals=1")

    os.system('start "" "photoshop.exe" "'+os.path.normcase(exportFile)+'"')
Esempio n. 12
0
    def __init__(self):

        # VAR SETUP#
        self.padding = 3
        self.fileType = {0: "mayaAscii", 1: "mayaBinary"}

        self.discipline_lut = {
            "MDL": "model",
            "LAYOUT": "layout",
            "ANIM": "anim",
            "PREVIS": "previs",
            "LGT": "lighting",
            "LOOKDEV": "lighting",
            "FX": "fx",
            "MM": "matchmove",
            "EXPORT": "export",
            "SHADING": "shading",
            "RP": "rigPuppet",
            "RS": "rigSkeleton",
            "RB": "rigBound",
            "TECHANIM": "techAnim",
        }

        self.file_path = cmds.file(q=True, sn=True)
        self.origFolder = os.path.dirname(self.file_path)
        self.origFilename = os.path.splitext(os.path.basename(self.file_path))[0]
        self.user = gp.getuser()
        self.folder_project = pm.workspace(q=True, rd=True)

        self.shot = "_".join(self.folder_project.split(os.path.sep)[-2:][:-1])
        self.discipline = "MDL"
        self.description = "_".join(
            self.origFilename.split(".")[0].split("_")[: self._findDescrIndex(self.origFilename)]
        )
        self.version = 1
        self.initials = self.user.split("-")[0][0] + self.user.split("-")[-1:][0]
        self.optional = None
        self.extension = "ma"

        self.file = ""
        self.optionalNote = None
        self.versionOption_startup = 1
        self.newFile = 0

        self._initialize()
Esempio n. 13
0
def cMuscle_makeMuscleSystem(meshes, prompt):
	if len(meshes) <= 0:
		pm.warning('No meshes were provided...')
		return False
	
	for mesh in meshes:
		muscleDeformer = mesh.getShape().listConnections(s=True, d=False, type='cMuscleSystem')
		if len(muscleDeformer):
			pm.warning('Already have a muscle deformer on this mesh...')
			return False
		muscleDeformer = pm.deformer(mesh, type='cMuscleSystem')[0]
		pm.PyNode('time1').outTime.connect(muscleDeformer.inTime)
		
		path = pm.workspace(q=True, dir=True) + 'muscleCache/'
		if not os.path.exists(path):
			os.makedirs(path)
		
		muscleDeformer.cachePath.set(path+mesh+'.mus')
		
		for attr in ['STICKY','SLIDING','JIGGLE','DISPLACE','FORCE','RELAX','SMOOTH','COLLISION']:
			muscleDeformer.attr(attr).lock()
		
		#relax now
		cMuscle_prepareRelax(mesh)
		
		skins = cMuscle_getDeformers('skinCluster', mesh)
		
		if prompt and len(skins) >= 1:
			labelYes = mel.eval('uiRes("m_cMuscle.kYes")')
			labelYes = mel.eval('uiRes("m_cMuscle.kNo")')
			ret = pm.confirmDialog(t=mel.eval('uiRes("m_cMuscle.kSetupForRelativeDeformation")'),
			                       m=mel.eval('uiRes("m_cMuscle.kThisMeshAppearsToHaveSkinClusterApplied")'),
			                       button = [labelYes, labelNo],
			                       defaultButton = labelYes,
			                       cancelButton = labelNo,
			                       dismissString = labelNo)
			if ret == labelYes:
				cMuscle_setupSystemforRelative(muscleDeformer)
		
		msg = mel.eval('uiRes("m_cMuscle.kAddedDef")')
		print msg
		return muscleDeformer
Esempio n. 14
0
def UI():
    if pm.window('pbudk', exists=True):
        pm.deleteUI('pbudk')

    optspath = '%s/pbUDK.json' % pm.internalVar(usd=True)
    defaultdata = {'phyType': 1,
                   'maxVerts': 32,
                   'center': True,
                   'child': True,
                   'fbxPath': '%sdata/' % pm.workspace(q=True, rd=True),
                   'presetFile': '%s/UDKexport/UDK-FBX.fbxexportpreset' % pm.internalVar(usd=True),
                   'version': version,
                   'prefix': False,
                   'prefix_text': '',
                   'suffix': False,
                   'suffix_text': ''}

    with pm.window('pbudk', title="{0} - {1}".format(title, version), width=250, sizeable=True) as window:
        with pm.columnLayout():
            opts = JSONDict(optspath, defaultdata)
            PhyUI(opts)
            FbxUI(opts)
        window.show()
Esempio n. 15
0
	def launch(self, *args, **kwargs):
		"""launch renderer command
		"""
		# do nothing if there is no window (called externally)
		if not self.window:
			return

		# get values
		start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
		end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
		frames_per_task = \
			pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
		by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
		hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
		hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
		separate_layers = \
			pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
		pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

		# check values
		if start_frame > end_frame:
			temp = end_frame
			end_frame = start_frame
			start_frame = temp

		frames_per_task = max(1, frames_per_task)
		by_frame = max(1, by_frame)

		# store field values
		pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
		pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
		pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
		pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
		pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
		pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
		pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

		# get paths
		scene_name = pm.sceneName()
		datetime = '%s%s' % (
			time.strftime('%y%m%d-%H%M%S-'),
			str(time.time() - int(time.time()))[2:5]
		)

		filename = '%s.%s.mb' % (scene_name, datetime)

		project_path = pm.workspace(q=1, rootDirectory=1)

		outputs = ','.join(
			pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)
		)

		job_name = os.path.basename(scene_name)

		logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
		logger.debug('scene        = %s' % scene_name)
		logger.debug('file         = %s' % filename)
		logger.debug('job_name     = %s' % job_name)
		logger.debug('project_path = %s' % project_path)
		logger.debug('outputs      = %s' % outputs)

		if pm.checkBox('cgru_afanasy__close', q=1, v=1):
			pm.deleteUI(self.window)

		cmd_buffer = [
			'"%(filename)s"',
			'%(start)s',
			'%(end)s',
			'-by %(by_frame)s',
			'-hostsmask %(msk)s',
			'-hostsexcl %(exc)s',
			'-fpt %(fpt)s',
			'-name "%(name)s"',
			'-pwd "%(pwd)s"',
			'-proj "%(proj)s"',
			'-images "%(images)s"',
			'-deletescene'
		]

		kwargs = {
			'filename': filename,
			'start': start_frame,
			'end': end_frame,
			'by_frame': by_frame,
			'msk': hosts_mask,
			'exc': hosts_exclude,
			'fpt': frames_per_task,
			'name': job_name,
			'pwd': project_path,
			'proj': project_path,
			'images': outputs
		}

		drg = pm.PyNode('defaultRenderGlobals')
		render_engine = drg.getAttr('currentRenderer')
		if render_engine == 'mentalRay':
			cmd_buffer.append('-type maya_mental')
		elif render_engine == 'arnold':
			cmd_buffer.append('-type maya_arnold')
			# set the verbosity level to warning+info
			aro = pm.PyNode('defaultArnoldRenderOptions')
			aro.setAttr('log_verbosity', 1)

		if pause:
			cmd_buffer.append('-pause')

		# save file
		pm.saveAs(
			filename,
			force=1,
			type='mayaBinary'
		)

		# rename back to original name
		pm.renameFile(scene_name)

		cmds = []

		# submit renders
		if separate_layers:
			# render each layer separately
			rlm = pm.PyNode('renderLayerManager')
			layers = [layer for layer in rlm.connections()
					  if layer.renderable.get()]

			for layer in layers:
				layer_name = layer.name()
				kwargs['name'] = '%s:%s' % (job_name, layer_name)

				tmp_cmd_buffer = copy.copy(cmd_buffer)
				tmp_cmd_buffer.append(
					'-take %s' % layer.name()
				)

				# create one big command
				afjob_cmd = ' '.join([
					os.environ['CGRU_PYTHONEXE'],
					'"%s/python/afjob.py"' % os.environ['AF_ROOT'],
					'%s' % ' '.join(tmp_cmd_buffer) % kwargs
				])
				cmds.append(afjob_cmd)

		else:
			# create one big command
			afjob_cmd = ' '.join([
				os.environ['CGRU_PYTHONEXE'],
				'%s/python/afjob.py' % os.environ['AF_ROOT'],
				'%s' % ' '.join(cmd_buffer) % kwargs
			])
			cmds.append(afjob_cmd)

		# call each command separately
		for cmd in cmds:
			print(cmds)

			os.system(cmd)
Esempio n. 16
0
	def launch(self, *args, **kwargs):
		"""launch renderer command
		"""
		# do nothing if there is no window (called externally)
		if not pm.window('cgru_afanasy_wnd', ex= 1):
			return

		# get values
		separate_layers = pm.checkBox('af_separate', q=1, v=1)
		start_frame = int(pm.floatField('af_strFrmFfd', q=1, v=1))
		end_frame = int(pm.floatField('af_endFrmFfd', q=1, v=1))
		frames_per_task = pm.intField('af_frmPTask_F', q=1, v=1)
		by_frame = int(pm.floatField('af_stpFrmFfd', q=1, v=1))
		hosts_mask = pm.textField('af_hostMask_F', q=1, text=1)
		hosts_exclude = pm.textField('af_hostExcl_F', q=1, text=1)
		priority = pm.intField('af_priority_F', q=1, v=1)
		pause = pm.checkBox('af_paused', q=1, v=1)
		close = pm.checkBox('af_close', q=1, v=1)

		# check values
		if start_frame > end_frame:
			temp = end_frame
			end_frame = start_frame
			start_frame = temp

		frames_per_task = max(1, frames_per_task)
		by_frame = max(1, by_frame)

		# store field values
		pm.optionVar['af_separate_layer_ov'] = separate_layers
		pm.optionVar['af_frmPTask_F_ov'] = frames_per_task
		pm.optionVar['af_hostMask_F_ov'] = hosts_mask
		pm.optionVar['af_hostExcl_F_ov'] = hosts_exclude
		pm.optionVar['af_priority_F_ov'] = priority
		pm.optionVar['af_paused_ov'] = pause
		pm.optionVar['af_close_ov'] = close

		# get paths
		scene_name = pm.sceneName()
		datetime = '%s%s' % (
			time.strftime('%y%m%d-%H%M%S-'),
			str(time.time() - int(time.time()))[2:5]
		)

		filename = '%s.%s.mb' % (scene_name, datetime)

		project_path = pm.workspace(q=1, rootDirectory=1)

		# ############################################################################
		# maya images folder root, a default path for not separate_layers
		# changed by DavidPower
		outputs = pm.workspace(q= 1, rd= 1) + pm.workspace('images', q= 1, fre= 1)
		# ############################################################################

		job_name = os.path.basename(scene_name)

		logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
		logger.debug('scene        = %s' % scene_name)
		logger.debug('file         = %s' % filename)
		logger.debug('job_name     = %s' % job_name)
		logger.debug('project_path = %s' % project_path)
		logger.debug('outputs      = %s' % outputs)

		if pm.checkBox('af_close', q=1, v=1):
			pm.deleteUI('cgru_afanasy_wnd')

		cmd_buffer = [
			'"%(filename)s"',
			'%(start)s',
			'%(end)s',
			'-by %(by_frame)s',
			'-hostsmask "%(msk)s"',
			'-hostsexcl "%(exc)s"',
			'-fpt %(fpt)s',
			'-name "%(name)s"',
			'-priority %(prio)s',
			'-pwd "%(pwd)s"',
			'-proj "%(proj)s"',
			'-images "%(images)s"',
			'-deletescene'
		]

		kwargs = {
			'filename': filename,
			'start': start_frame,
			'end': end_frame,
			'by_frame': by_frame,
			'msk': hosts_mask,
			'exc': hosts_exclude,
			'fpt': frames_per_task,
			'name': job_name,
			'prio': priority,
			'pwd': project_path,
			'proj': project_path,
			'images': outputs
		}

		drg = pm.PyNode('defaultRenderGlobals')
		if drg.getAttr('currentRenderer') == 'mentalRay':
			cmd_buffer.append('-type maya_mental')

		if pause:
			cmd_buffer.append('-pause')

		#-----------------------------#
		currentRenderer = pm.PyNode('defaultRenderGlobals').getAttr('currentRenderer')
		sn = os.path.basename(cmds.file(q= 1, exn= 1)).split('.')[0]
		imgPrefix = pm.getAttr('vraySettings.fileNamePrefix') if currentRenderer == 'vray' else pm.getAttr('defaultRenderGlobals.imageFilePrefix')
		tmpPrefix = imgPrefix.replace('<Scene>', sn)
		if currentRenderer == 'vray':
			pm.setAttr('vraySettings.fileNamePrefix', tmpPrefix)
		else:
			pm.setAttr('defaultRenderGlobals.imageFilePrefix', tmpPrefix)
		#-----------------------------#

		# save file
		pm.saveAs(
			filename,
			force=1,
			type='mayaBinary'
		)

		#-----------------------------#
		if currentRenderer == 'vray':
			pm.setAttr('vraySettings.fileNamePrefix', imgPrefix)
		else:
			pm.setAttr('defaultRenderGlobals.imageFilePrefix', imgPrefix)
		#-----------------------------#

		# rename back to original name
		pm.renameFile(scene_name)

		cmdList = []

		# submit renders
		if separate_layers:
			# render each layer separately
			rlm = pm.PyNode('renderLayerManager')
			layers = [layer for layer in rlm.connections()
					  if layer.renderable.get()]

			for layer in layers:
				layer_name = layer.name()
				kwargs['name'] = '%s:%s' % (job_name, layer_name)

				# ############################################################################
				# update images path for each layers, and fix outputs if renderer is vray
				# changed by DavidPower
				kwargs['images'] = self.dpaf_outputsFix(layer)
				# ############################################################################

				kwargs['start'] = int(self.dpaf_getOverrideData('defaultRenderGlobals.startFrame', layer_name))
				kwargs['end'] = int(self.dpaf_getOverrideData('defaultRenderGlobals.endFrame', layer_name))
				kwargs['by_frame'] = int(self.dpaf_getOverrideData('defaultRenderGlobals.byFrameStep', layer_name))

				tmp_cmd_buffer = copy.copy(cmd_buffer)
				tmp_cmd_buffer.append(
					'-take %s' % layer.name()
				)

				# create one big command
				afjob_cmd = ' '.join([
					os.environ['CGRU_PYTHONEXE'],
					'"%s/python/afjob.py"' % os.environ['AF_ROOT'],
					'%s' % ' '.join(tmp_cmd_buffer) % kwargs
				])
				cmdList.append(afjob_cmd)

		else:
			# create one big command
			afjob_cmd = ' '.join([
				os.environ['CGRU_PYTHONEXE'],
				'%s/python/afjob.py' % os.environ['AF_ROOT'],
				'%s' % ' '.join(cmd_buffer) % kwargs
			])
			cmdList.append(afjob_cmd)

		# call each command separately
		for cmd in cmdList:
			print(cmdList)

			os.system(cmd)
Esempio n. 17
0
'''
Created on Nov 25, 2014

@author: qurban.ali
         talha.ahmed
'''
import os
import sys
import pymel.core as pc
import re

import iutil

mapFiles = '''#ICE_BundleScript
#version==0.4
import pymel.core as pc
import maya.cmds as cmds
import os.path as osp
import os

rootPath = osp.dirname(osp.dirname(cmds.file(q=True, location=True)))
refRootPath = osp.normpath(osp.join(rootPath, "scenes", "refs"))

msg = False
pc.workspace(rootPath, o=True)

for node in pc.ls(type="reference"):
    if not node.referenceFile():
        continue
    try:
        fNode = pc.FileReference(node)
Esempio n. 18
0
    def __init__(self, **kwds):

        self.character = defaultReturn('jerry', 'character', param=kwds)
        self.model = defaultReturn(None, 'model', param=kwds)
        self.skeleton = defaultReturn(None, 'skeleton', param=kwds)

        self.mayaScene = self.character + '_rigBound_buildScene'

        self.makeBiped = defaultReturn(False, 'biped', param=kwds)
        self.makeQuadruped = defaultReturn(False, 'quadruped', param=kwds)

        pm.newFile(f=True)

        print "START: rigBound build " + self.character
        pm.timer(s=True)
        pm.undoInfo(state=False)
        pm.evaluationManager(mode='serial')

        try:
            self.charModule = importlib.import_module('char.' +
                                                      self.character + 'Bound')
            print self.charModule

            pm.workspace(update=True)
            projectRoot = pm.workspace(q=True, rd=True) + 'scenes/release/'
            print ' project root ' + projectRoot + ' found'

            modelPath = projectRoot + 'model/' + self.character + '/'
            if self.model is None:
                fileList = []
                os.chdir(modelPath)
                for f in glob.glob("*.ma"):
                    fileList.append(f)

                fileList.sort()
                latestFile = fileList[-1:][0]
                print fileList
                self.model = modelPath + latestFile
            else:
                self.model = modelPath + self.model + '.ma'

            print 'model file path = ' + self.model
            # import model file
            try:
                filePath = cmds.file(self.model,
                                     i=True,
                                     ignoreVersion=True,
                                     ra=False,
                                     mergeNamespacesOnClash=False,
                                     typ="mayaAscii",
                                     loadReferenceDepth='none')
            except RuntimeError:
                print self.model + ' file not found'

            cmds.dgdirty(allPlugs=True)
            cmds.refresh()

            skeletonPath = projectRoot + 'rigSkeleton/' + self.character + '/'
            if self.skeleton is None:
                fileList = []
                os.chdir(skeletonPath)
                for f in glob.glob("*.ma"):
                    fileList.append(f)

                fileList.sort()
                latestFile = fileList[-1:][0]
                self.skeleton = skeletonPath + latestFile
            else:
                self.skeleton = skeletonPath + self.skeleton + '.ma'

            print 'skeleton file path = ' + self.skeleton
            # import skeleton file
            try:
                filePath = cmds.file(self.skeleton,
                                     i=True,
                                     ignoreVersion=True,
                                     ra=False,
                                     mergeNamespacesOnClash=False,
                                     typ="mayaAscii",
                                     loadReferenceDepth='none')
            except RuntimeError:
                print self.skeleton + ' file not found'

            cmds.dgdirty(allPlugs=True)
            cmds.refresh()

            # unparent skeleton
            #skeleton = pm.listRelatives('skeleton_GRP', typ='joint')

            self.globalCtrl = rig_control(name='global',
                                          colour='white',
                                          shape='arrows',
                                          con=0,
                                          showAttrs=['sx', 'sy', 'sz'])

            self.topNode = rig_transform(0,
                                         name=self.character + 'RigBoundTop',
                                         child=self.globalCtrl.offset).object

            self.rigGrp = rig_transform(0,
                                        name='rig',
                                        parent=self.globalCtrl.ctrl).object
            pm.addAttr(self.rigGrp,
                       longName='worldScale',
                       at='float',
                       k=True,
                       min=0,
                       defaultValue=1)
            #self.rigGrp.worldScale.set(cb=True)
            pm.connectAttr(self.globalCtrl.ctrl.scaleX,
                           self.rigGrp + '.worldScale')

            self.modelGrp = rig_transform(0, name='model',
                                          parent=self.topNode).object
            self.modelGrp = pm.PyNode(self.modelGrp)

            self.rigModel = rig_transform(0,
                                          name='rigModel',
                                          parent=self.modelGrp).object

            #self.skeleton = rig_transform(0, name='skeleton', parent=self.globalCtrl.ctrl, child=skeleton).object
            self.skeleton = 'skeleton_GRP'
            pm.parent('skeleton_GRP', self.globalCtrl.ctrl)

            pm.parent('allModel_GRP', self.modelGrp)

            # create attributes on global ctrl
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='boundSettings',
                       at='enum',
                       enumName='___________',
                       k=True)
            self.globalCtrl.ctrl.boundSettings.setLocked(True)

            # model and skeleton vis
            # model

            print(self.modelGrp)
            connectAttrToVisObj(self.globalCtrl.ctrl,
                                'modelVis',
                                self.modelGrp,
                                defaultValue=1)
            # skeleton
            connectAttrToVisObj(self.globalCtrl.ctrl,
                                'skeletonVis',
                                self.skeleton,
                                defaultValue=1)

            # referencing and selecting
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='model',
                       at='enum',
                       enumName='Selectable:Reference',
                       k=True,
                       defaultValue=1)
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='skeleton',
                       at='enum',
                       enumName='Selectable:Reference',
                       k=True,
                       defaultValue=1)

            # LOD vis
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='lodSetting',
                       at='enum',
                       enumName='___________',
                       k=True)
            self.globalCtrl.ctrl.lodSetting.setLocked(True)
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='lodDisplay',
                       at='enum',
                       enumName='Low:Mid:High',
                       k=True,
                       defaultValue=0)

            lodModel = [
                'lowLOD_GRP', 'lowMidLOD_GRP', 'midLOD_GRP', 'midHighLOD_GRP',
                'highLOD_GRP'
            ]

            for lod in lodModel:
                if pm.objExists(lod):
                    lodGRP = pm.PyNode(lod)
                    pm.parent(lodGRP, self.modelGrp)
                    if 'low' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=0)
                    if 'mid' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=0)
                    if 'high' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=1)
                    if 'lowMid' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=0)
                    if 'midHigh' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=1)

            # scale global control
            self.bbox = self.modelGrp.boundingBox()
            width = self.bbox.width() * 0.3
            cvsGlobal = pm.PyNode(self.globalCtrl.ctrl + '.cv[:]')
            pm.scale(cvsGlobal, width, width, width)

            try:
                pm.delete("|*RigSkeletonTop_GRP")
            except pm.MayaNodeError:
                print 'RigSkeleton top node does not exist'

            pm.hide(self.rigGrp, self.rigModel)

            self.prepareRig()

            self.createRigModules()

            self.finishRig()

            pm.select(cl=True)

            self.sup = super(bound, self)
            self.sup.__init__(self.topNode, **kwds)

        except Exception as e:
            print "*************************************"
            print "=========== Error happened ========="
            raise
        finally:
            pm.evaluationManager(mode='parallel')

            mayaTimer = pm.timer(e=True)

            pm.undoInfo(state=True)
            print ''
            print ''
            print "END: rigBound built in %g seconds" % mayaTimer
            print ''
Esempio n. 19
0
 def output_dir(self, filepath):
     if not filepath:
         self._output_dir = pm.workspace(q=True, fullName=True)
     else:
         self._output_dir = filepath
Esempio n. 20
0
            else:
                raise
        else:
            if res is not None:
                path = res

    #print path, tokens
    partialPath = expandFileTokens(path,
                                   tokens,
                                   leaveUnmatchedTokens=leaveUnmatchedTokens)
    if pathType in [
            pm.api.MCommonRenderSettingsData.kRelativePath, 'relative'
    ]:
        return partialPath

    imageDir = pm.workspace(fileType, q=True, fileRuleEntry=True)
    imageDir = imageDir if imageDir else 'data'
    imageDir = pm.workspace(expandName=imageDir)

    if pathType in [pm.api.MCommonRenderSettingsData.kFullPathTmp, 'temp']:
        result = os.path.join(imageDir, 'tmp', partialPath)
    elif pathType in [pm.api.MCommonRenderSettingsData.kFullPathImage, 'full']:
        result = os.path.join(imageDir, partialPath)
    else:
        raise TypeError("Invalid pathType")

    result = result.replace("\\", "/")
    if createDirectory:
        dir = os.path.dirname(result)
        try:
            os.makedirs(dir)
Esempio n. 21
0
    def __init__(self, wn, jobtype, *a):
        
        self.jobtype = jobtype

        self.submit_dict = getSceneData(jobtype)

        self.default_name = pm.sceneName().basename().rstrip('.mb')

        #################################################################################
        ## UI LAYOUT
        #################################################################################
        
        self.setTitle('Submit Scene to Qube')
        self.setToolbox()
        #self.setResizeToFitChildren(1)
        self.setSizeable(0)
        self.setHeight(250)

        main_layout = pm.formLayout(p=self)

        # input / output paths
        column = pm.formLayout(p=main_layout)


        self.job_text = pm.textFieldGrp(
            'job_text',
            label='Job Name', 
            text=self.submit_dict['name'], 
            cc=self.setName, 
            tcc=self.setName,
            p=column,
            cw2=(110,655)
            )
        self.scene_text = pm.textFieldGrp(
            'scene_text',
            label='Scene File', 
            text=self.submit_dict['package']['scenefile'], 
            cc=self.setScenePath, 
            tcc=self.setScenePath,
            p=column,
            cw2=(110,655)
            )
        self.project_text = pm.textFieldGrp(
            'project_text',
            label='Project Path', 
            text=pathFormat(pm.workspace(q=True, rd=True).replace('/','\\')),
            ed=False,
            p=column,
            cw2=(110,655)
            )
        self.outdir_text = pm.textFieldGrp(
            'outdir_text',
            label='Render Path (optional)', 
            text='',
            cc=self.setRenderPath,
            p=column,
            cw2=(110,655)
            )
        column.redistribute()

        # 2 columns
        column = pm.formLayout(p=main_layout)
        column.flip()
        rows = pm.formLayout(p=column)
       
        # frame range
        self.frange_text = pm.textFieldGrp(
            'frange_text',
            l='Frame Range', 
            text=self.submit_dict['package']['range'], 
            cc=self.setRange,
            tcc=self.setRange,
            cw2=(110, 80), 
            p=rows
            )
        if self.jobtype == 'mayacmd':
            self.chunk_text = pm.textFieldGrp(
                'chunk_text',
                l='Chunk Size',
                text=default_chunk,
                cc=self.setChunk,
                tcc=self.setChunk,
                cw2=(110, 80),
                p=rows
                )
        else: pass

        # num. threads
        threads_col = pm.rowLayout(p=rows, nc=2)
        self.threads_text = pm.textFieldGrp(
            'threads_text',
            l='Num. Threads',
            text=default_threads,
            tcc=self.setThreads,
            cw2=(110, 40),
            p=threads_col
            )
        self.threads_text.setEnable(0)

        self.threads_chkbox = pm.checkBox(
            'threads_chkbox',
            l='All',
            value=default_allcores,
            cc=self.setThreads,
            p=threads_col
            )

        # priority
        self.priority_text = pm.textFieldGrp(
            'priority_text',
            l='Priority', 
            text=default_priority, 
            cc=self.setPriority,
            tcc=self.setPriority,
            cw2=(110, 80),
            p=rows)

        # cluster
        cluster_col = pm.rowLayout(p=rows, nc=2)
        self.cluster_text = pm.textFieldGrp(
            'cluster_text',
            l='Cluster', 
            text='/',
            cc=self.setCluster,
            tcc=self.setCluster,
            cw2=(110, 40), 
            p=cluster_col
            )
        self.restrict_chkbox = pm.checkBox(
            'restrict_chkbox',
            l='Restrict?',
            value=False,
            cc=self.setCluster,
            p=cluster_col
            )
        self.restrict_text = pm.textFieldGrp(
            'restrict_text',
            l='Restrict to Clusters',
            text='',
            cc=self.setCluster,
            tcc=self.setCluster,
            cw2=(110, 80),
            enable=False,
            p=rows
            )
        rows.redistribute()

        rows = pm.formLayout(p=column)
        self.submit_btn = pm.button(label='Submit Current Layer', height=10, c=self.submit, p=rows)
        self.submit_all_btn = pm.button(label='Submit All Renderable Layers', height=10, c=self.submit_all, p=rows)
        rows.redistribute()       
 
        column.redistribute(1,2)

        main_layout.redistribute(1,1.5)

        self.setThreads()
Esempio n. 22
0
def importSkin(filePath=None, *args):

    if not filePath:
        startDir = pm.workspace(q=True, rootDirectory=True)
        filePath = pm.fileDialog2(dialogStyle=2,
                                  fileMode=1,
                                  startingDirectory=startDir,
                                  fileFilter='mGear Skin (*%s)' % FILE_EXT)
    if not filePath:
        return
    if not isinstance(filePath, basestring):
        filePath = filePath[0]

    # Read in the file
    fh = open(filePath, 'rb')
    dataPack = pickle.load(fh)
    fh.close()

    for data in dataPack["objDDic"]:

        try:
            skinCluster = False
            objName = data["objName"]
            objNode = pm.PyNode(objName)

            try:
                meshVertices = pm.polyEvaluate(objNode, vertex=True)
                importedVertices = len(data['blendWeights'])
                if meshVertices != importedVertices:
                    pm.displayWarning('Vertex counts do not match. %d != %d' %
                                      (meshVertices, importedVertices))
                    continue
            except Exception:
                pass

            if getSkinCluster(objNode):
                skinCluster = getSkinCluster(objNode)
            else:
                try:
                    joints = data['weights'].keys()
                    skinCluster = pm.skinCluster(joints,
                                                 objNode,
                                                 tsb=True,
                                                 nw=2,
                                                 n=data['skinClsName'])
                except Exception:
                    notFound = data['weights'].keys()
                    sceneJoints = set(
                        [pm.PyNode(x).name() for x in pm.ls(type='joint')])

                    for j in notFound:
                        if j in sceneJoints:
                            notFound.remove(j)
                    pm.displayWarning("Object: " + objName + " Skiped. Can't "
                                      "found corresponding deformer for the "
                                      "following joints: " + str(notFound))
                    continue
            if skinCluster:
                setData(skinCluster, data)
                print 'Imported skin for: %s' % objName

        except Exception:
            pm.displayWarning("Object: " + objName + " Skiped. Can NOT be "
                              "found in the scene")
Esempio n. 23
0
def saveAllRenderViewImages( saveTo=None, ext='PNG' ):
    '''
    렌더뷰에 임시저장된 이미지들을 따로 몽땅 저장

    saveAllRenderViewImages( 'D:/Users/Desktop/hello', ext='png')
    saveAllRenderViewImages( 'D:/Users/Desktop/hello.png' )
    '''
    # 렌더뷰 컨트롤 찾기
    renderViewPanels = pm.getPanel( scriptType='renderWindowPanel' )
    if not renderViewPanels:
        pm.error( u"Render View window를 열어주세요." )

    renderViewPanel = renderViewPanels[0]
    renderViewForm = pm.renderWindowEditor( renderViewPanel, q=True, parent=True )
    if not renderViewForm:
        pm.error( u"Render View window를 열어주세요." )

    scrollBarName = '|'.join( renderViewForm.split('|')[:-1] ) + '|scrollBarForm|scrollBar'

    # 어디다 저장할지?
    dirname = None
    basename = None
    padding = 4
    if not saveTo:
        ws      = pm.workspace( q=True, fullName=True )
        images  = pm.workspace( 'images', q=True, fileRuleEntry=True)
        dirname = ws + '/' + images
        basenameEx = '/renderViewCapture'
    else:
        # path = r'Z:\2013_MapleStory2\3D_project\Share\scenes\GameData\Alon.mb'
        dirname    = os.path.dirname( saveTo )
        basename   = os.path.basename( saveTo )
        basenameEx = None
        if '.' in basename:
            basenameEx = '.'.join( basename.split('.')[:-1] )
            ext        = basename.split('.')[-1]
        else:
            basenameEx = basename

        if not os.path.isdir( dirname ):
            pm.error( u'그런 이름의 디렉토리는 없네용' )

    # numPadding
    padding    = basenameEx.count('#')
    basenameEx = basenameEx.replace('#','')
    paddingStr = '%d'
    if padding > 1:
        paddingStr = '%0' + str(padding) +'d'        

    saveTo = dirname + '/' + basenameEx + paddingStr +'.'+ ext.lower()
    #print 'name : "%s"' % saveTo

    # 지금 보고있는 렌더뷰 이미지가 어디 있는지 찾아야해용.
    # 그래서 하나하나 뒤로 돌려봅네당..
    currentIndex = pm.intScrollBar( scrollBarName, q=True, value=True )

    # now step through all the saved images in the render view window, saving each one out
    #int $maxImageIndex = `intScrollBar -query -maxValue $scrollBarName`;
    maxImageIndex = pm.renderWindowEditor( 'renderView', q=True, nbImages=True )    
    imagesWritten = 0
    number = 0 # 파일명이 겹치지 않도록 하는 변수
    for i in range( maxImageIndex+1 ):
        if not maxImageIndex == 0:
            # 한장의 이미지만 있고, 스크롤바가 안생긴 상태가 아니면...
            pm.intScrollBar( scrollBarName, e=True, value=i-1 )

        # 저장될 파일명
        number += 1
        fileName = saveTo % number
        
        # 같은 파일명의 이름이 있으면 뒤에 번호를 더 붙임
        while os.path.exists(fileName):
            #print '"%s" is Exists' % fileName
            number += 1
            fileName = saveTo % number
        
        # 저장
        pm.mel.renderWindowScrollDisplayImage( 'renderView' )
        pm.mel.renderWindowSaveImageCallback( 'renderView', fileName, ext.upper() )
        
        # 내용 출력
        print '# save To : %s' % fileName.replace('/','\\')
        
        # 저장된 이미지 개수 증가
        imagesWritten += 1
    
    # reset the current render view back to what it was before stepping through them
    pm.intScrollBar( scrollBarName, e=True, value=currentIndex )
    pm.mel.renderWindowScrollDisplayImage( 'renderView' )

    if imagesWritten == 0:
        print u"# Error saving: render view 에 이미지가 없습니다.\n"
    else:
        print u"# Save complete: %d장의 render view 이미지가 저장 되었습네다.\n"%imagesWritten
Esempio n. 24
0
def getImagesLocation(workspace=None):
    if workspace:
        return pc.workspace(workspace,
                            en=pc.workspace(workspace, fre='images'))
    else:
        return pc.workspace(en=pc.workspace(fre='images'))
Esempio n. 25
0
def setProjectPath(path):
    if op.exists(path):
        pc.workspace(e=True, o=path)
        return True
Esempio n. 26
0
def getProjectPath():
    return pc.workspace(q=True, o=True)
Esempio n. 27
0
 def __init__(self):
     
     #VAR SETUP#
     self.fileType={0:"mayaAscii", 1:"mayaBinary"}
     self.disciplines=['MDL','LAYOUT','ANIM','PREVIS','LGT','FX','MM','SHADING','TECHANIM','LOOKDEV','EXPORT','RP','RS','RB']
     self.disciplineDirs={'MDL':'model','LAYOUT':'layout','ANIM':'anim','PREVIS':'previs','LGT':'lighting','LOOKDEV':'lighting','FX':'fx','MM':'matchmove','EXPORT':'export','SHADING':'shading','RP':'rigPuppet','RS':'rigSkeleton','RB':'rigBound','TECHANIM':'techAnim'}
     self.filePath = os.path.abspath( cmds.file(q=True, sn=True) )
     self.origFolder = os.path.dirname(self.filePath)
     self.origFilename = self.filePath.split('/')[-2:][1].split('.')[0]
     self.username = gp.getuser()
     self.newFile=0
     self.folder_project = os.path.abspath( pm.workspace( q=True, rd=True ) )
     self.shot = '_'.join( self.folder_project.split( os.path.sep )[-2:][:-1] )
     self.folder_discipline = os.path.join( 'scenes','model' )
     self.optionalNote=''
     self.versionOption_startup=1
     
     self._parseFileName()
     
     
     #UI SETUP#
     title='AW_Save_Plus'
     self.go_green_cl=[.1,.4,.2]
     self.title_blue_cl=[.1,.15,.2]
     self.go_yellow_cl=[0.947, 0.638, 0.130]
     if(pm.windowPref(title, q=True, ex=True)):
         pm.windowPref(title, remove=True)
     if(pm.window(title, q=True,ex=True)):
         pm.deleteUI(title)
     self.window = pm.window(title,t=title, w=890, h=105)
     
     self.fl = pm.formLayout()
     self.title_tx = pm.symbolButton(image='save_105.png', w=105, h=105)
     self.col = pm.columnLayout(p=self.fl)
     pm.text(l='Saving to Directory:', fn='boldLabelFont')
     self._updateFile(False)
     self.filePath_tx = pm.text('filePath_tx', l=self.file)
     pm.text(l='')
     self.header = pm.text('header_tf',fn='boldLabelFont', l='Filename')
     self.origFile_om = wind.AW_optionMenu(label='', options=['Original Folder', 'Auto-detect'], parent=self.col, cc=self._changeOrigFolder_om)
     if self.newFile: self.origFile_om.setSelect(2)
     
     self.layout = pm.formLayout(nd=100)
     
     self.fileDescr_tf = pm.textField('fileDescr_tf',text=self.fileDescr, p=self.layout, w=200, cc=self._changeFileDescr)
     self.discipline_om = wind.AW_optionMenu(label='_', options=self.disciplines, parent=self.layout, cc=self._changeDiscipline)
     self.spacer = pm.text(l='_v', p=self.layout,w=10)
     self.version_tf = pm.textField('version_tf',text='%03d'%self.version, p=self.layout, w=30, cc= self._changeVersionNumber)
     self.versionOptional_om = wind.AW_optionMenu(label='', options=['','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'], parent=self.layout, cc=self._changeVersionOptional_om)
     self.optionalNote_tf = pm.textField('optionalNote_tf', text='(optional note)', p=self.layout, w=150, cc=self._changeOptionalNoteTx)
     self.type = wind.AW_optionMenu(label='_', options=['.ma','.mb'], parent=self.layout, cc=self._changeType_om)
     if self.initialFileType=='ma': self.type.setSelect(1)
     if self.initialFileType=='mb': self.type.setSelect(2)
     self.save_btn = pm.button(label='Save', command=self._save,h=20, bgc=self.go_yellow_cl)
   
     pm.formLayout(self.layout, e=True, af=[(self.fileDescr_tf, 'left', 0),
                                            (self.spacer,'top',5)],
                                            ac=[(self.discipline_om.optionMenu, 'left',5, self.fileDescr_tf),
                                                (self.spacer, 'left',5, self.discipline_om.optionMenu),
                                                (self.version_tf, 'left',5, self.spacer),
                                                (self.versionOptional_om.optionMenu, 'left',5,self.version_tf),
                                                (self.optionalNote_tf, 'left',5,self.versionOptional_om.optionMenu),
                                                (self.type.optionMenu, 'left',5,self.optionalNote_tf),
                                                (self.save_btn, 'left',5,self.type.optionMenu)])
     pm.formLayout(self.fl, e=True, af=[(self.col, 'top', 10)], ac=[(self.col, 'left',10, self.title_tx)])
     
     self._setVersionOption(self.versionOption_startup)
     self._getDiscipline()
     self._updateFilename()
     self._updateFilePathTx()
     
     self.window.show()
Esempio n. 28
0
def get_workspace_root():
    """
    :return: Get the workspace root and return its path.
    :rtype: str
    """
    return os.path.normpath(pm.workspace(query=True, rootDirectory=True))
Esempio n. 29
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [dAO.getAttr(attr) for attr in ignore_attrs]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x, y: '%s: %s' % (x, y),
                        ignore_attrs,
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)
        )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"',
            '%(start)s',
            '%(end)s',
            '-by %(by_frame)s',
            '-hostsmask %(msk)s',
            '-hostsexcl %(exc)s',
            '-fpt %(fpt)s',
            '-name "%(name)s"',
            '-pwd "%(pwd)s"',
            '-proj "%(proj)s"',
            '-images "%(images)s"',
            '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'pwd': project_path,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        if render_engine == 'mentalRay':
            cmd_buffer.append('-type maya_mental')
        elif render_engine == 'arnold':
            cmd_buffer.append('-type maya_arnold')
            # set the verbosity level to warnin+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', 1)

        if pause:
            cmd_buffer.append('-pause')

        # set output to console
        dARO = pm.PyNode('defaultArnoldRenderOptions')
        dARO.setAttr("log_to_console", 1)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # disable set output to console
        dARO.setAttr("log_to_console", 0)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append(
                    '-take %s' % layer.name()
                )

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 30
0
    def cmd_alterTxsPrf_bt(self):  #修改贴图前缀匹配当前项目
        u"""
        >>  根据maya文件名获取项目缩写,修改所有贴图前缀为项目缩写
                         同时修改 - 空格 等不规范字符
        """
        mod = {'RENAME OLD': 'rn', 'COPIED FOR NEW': 'cp'}
        result = mc.promptDialog(
            title='Texture Prefix',
            message='Enter Prefix:',
            button=['COPIED FOR NEW', 'RENAME OLD', 'Cancel'],
            defaultButton='OK',
            cancelButton='Cancel',
            dismissString='Cancel',
            text=self.proj_abbr)
        if result in mod:
            self.proj_abbr = mc.promptDialog(query=True, text=True)
        else:
            return
        ALL_PROJ_ABBRS = os.listdir(PROJ_DIR)
        alterFs = pm.selected(type='file')
        if not alterFs: alterFs = pm.ls(type='file')
        cur_proj_wsp = pm.workspace(fn=True, q=True)
        cur_src_dir = "{}/sourceimages/".format(cur_proj_wsp)
        all_cnt = len(alterFs)
        renmed_txs_cnt = 0
        prg_num = (renmed_txs_cnt + 1 / float(all_cnt)) * 100
        cpProgressWin = mc.progressWindow(
            title="Add Prefix",
            progress=prg_num,
            status="PROGRESS : {}%".format(prg_num),
            isInterruptable=True,
            min=0,
            max=100)
        res_error_str = ""
        modifiedTex = {}
        for eaf in alterFs:
            get_txfpths = []
            txfpth_01 = eaf.attr('fileTextureName').get()
            if txfpth_01.startswith("${"):
                txfpth_01 = self.k.txAbsPath(txfpth_01).values()[0]
            get_txfpths.append(txfpth_01)
            if_tx_file = self.get_ArTx(txfpth_01)
            if if_tx_file and os.path.isfile(if_tx_file):
                get_txfpths.append(if_tx_file)
            if eaf.attr('uvTilingMode').get() == 3 or eaf.attr(
                    'useFrameExtension').get():
                seqs = self.k.findTxSeqs(txfpth_01)
                if isinstance(seqs, str):
                    res_error_str += u'{0}>>>请检查 file节点 {1:<32} 的序列贴图是否存在或命名是否正确:\t{2} {0}'.format(
                        os.linesep, eaf.nodeName(), txfpth_01)
                else:
                    get_txfpths.extend(seqs[1:])
                if if_tx_file and os.path.isfile(if_tx_file):
                    tx_seqs = self.k.findTxSeqs(if_tx_file)
                    if isinstance(tx_seqs, str):
                        res_error_str += u'{0}>>>请检查 file节点 {1:<32} 的序列贴图是否存在或命名是否正确:\t{2} {0}'.format(
                            os.linesep, eaf.nodeName(), if_tx_file)
                    else:
                        get_txfpths.extend(tx_seqs[1:])
            print "node name {}".format(eaf.nodeName())
            for txfpth in get_txfpths:
                print " textrue file : {} ".format(txfpth)
                set_attr_value = True
                if get_txfpths.index(txfpth): set_attr_value = False
                txf_nm = os.path.basename(txfpth)
                txf_prj_abbr = re.search("^[^_]+", txf_nm).group()
                # if txf_prj_abbr == self.proj_abbr: continueW
                txf_dir = re.sub(txf_nm, '', txfpth)

                if not txf_dir == cur_src_dir and mod[result] == 'cp':
                    txf_dir = cur_src_dir
                new_txf_nm = None
                if txf_prj_abbr in ALL_PROJ_ABBRS:
                    txf_nm_norm = self.k.normalizeTxNm(txf_nm)
                    new_txf_nm = re.sub(txf_prj_abbr, self.proj_abbr,
                                        txf_nm_norm)
                else:
                    new_txf_nm = '{}_{}'.format(self.proj_abbr,
                                                self.k.normalizeTxNm(txf_nm))
                new_txf_pth = "{}{}".format(txf_dir, new_txf_nm)
                if txfpth in modifiedTex:
                    eaf.attr('fileTextureName').set(new_txf_pth)
                    continue
                if self.k.filetest(txfpth, new_txf_pth):
                    # print(">>>--{}{}>>>---{}".format(txfpth,os.linesep,new_txf_pth))
                    if mod[result] == 'cp':
                        try:
                            shutil.copy2(txfpth, new_txf_pth)
                            if set_attr_value:
                                eaf.attr('fileTextureName').set(new_txf_pth)
                            modifiedTex[txfpth] = new_txf_pth
                        except:
                            print(
                                "sorce image: {1}{0}target image: {2}".format(
                                    os.linesep, txfpth, new_txf_pth))
                            mc.progressWindow(cpProgressWin, endProgress=1)
                            res_error_str += u'{0}>>>请检查 file节点 {1:<32} 的贴图是否存在或命名是否正确:\t{2} >>>> new name : {3} {0}'.format(
                                os.linesep, eaf.nodeName(), txfpth,
                                new_txf_pth)

                    elif mod[result] == 'rn':
                        try:
                            eaf.attr('fileTextureName').set("")

                            os.rename(txfpth, new_txf_pth)
                            if set_attr_value:
                                eaf.attr('fileTextureName').set(new_txf_pth)
                            modifiedTex[txfpth] = new_txf_pth
                        except Exception, e:
                            print e.message
                            res_error_str += u'{0}>>>请检查 file节点 {1:<32} 的贴图 路径的写入权限:{2:<32} :\t{}{0}'.format(
                                os.linesep, eaf.nodeName(), txf_dir)
                            mc.progressWindow(cpProgressWin, endProgress=1)
                    renmed_txs_cnt += 1
                    self.ref_pr_bar(renmed_txs_cnt + 1, all_cnt, cpProgressWin)
                    # print(u">>>请检查 当前工程的sourceimages文件夹 是否存在并且有写入权限")
                else:
                    if os.path.exists(new_txf_pth):
                        if set_attr_value:
                            eaf.attr('fileTextureName').set(new_txf_pth)
                        renmed_txs_cnt += 1
                        self.ref_pr_bar(renmed_txs_cnt + 1, all_cnt,
                                        cpProgressWin)
Esempio n. 31
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [dAO.getAttr(attr) for attr in ignore_attrs]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x, y: '%s: %s' % (x, y), ignore_attrs,
                        attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1))

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"', '%(start)s', '%(end)s', '-by %(by_frame)s',
            '-hostsmask %(msk)s', '-hostsexcl %(exc)s', '-fpt %(fpt)s',
            '-name "%(name)s"', '-pwd "%(pwd)s"', '-proj "%(proj)s"',
            '-images "%(images)s"', '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'pwd': project_path,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        if render_engine == 'mentalRay':
            cmd_buffer.append('-type maya_mental')
        elif render_engine == 'arnold':
            cmd_buffer.append('-type maya_arnold')
            # set the verbosity level to warnin+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', 1)

        if pause:
            cmd_buffer.append('-pause')

        # set output to console
        dARO = pm.PyNode('defaultArnoldRenderOptions')
        dARO.setAttr("log_to_console", 1)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # disable set output to console
        dARO.setAttr("log_to_console", 0)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append('-take %s' % layer.name())

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 32
0
def showUI():
    # path = pm.mel.eval("pwd") #  path to script
    path = pm.workspace(q=True, rootDirectory=True)

    ui = TurntableUI()
    ui.show()
Esempio n. 33
0
    def launch(self, *args, **kwargs):
        """launch renderer command
		"""
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
         pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
         pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers'] = separate_layers

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = ','.join(
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1))

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        cmd_buffer = [
            '"%(filename)s"', '%(start)s', '%(end)s', '-by %(by_frame)s',
            '-hostsmask %(msk)s', '-hostsexcl %(exc)s', '-fpt %(fpt)s',
            '-name "%(name)s"', '-proj "%(proj)s"', '-images "%(images)s"',
            '-deletescene'
        ]

        kwargs = {
            'filename': filename,
            'start': start_frame,
            'end': end_frame,
            'by_frame': by_frame,
            'msk': hosts_mask,
            'exc': hosts_exclude,
            'fpt': frames_per_task,
            'name': job_name,
            'proj': project_path,
            'images': outputs
        }

        drg = pm.PyNode('defaultRenderGlobals')
        if drg.getAttr('currentRenderer') == 'mentalRay':
            cmd_buffer.append('-type maya_mental')

        if pause:
            cmd_buffer.append('-pause')

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        cmds = []

        # submit renders
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                layer_name = layer.name()
                kwargs['name'] = '%s:%s' % (job_name, layer_name)

                tmp_cmd_buffer = copy.copy(cmd_buffer)
                tmp_cmd_buffer.append('-take %s' % layer.name())

                # create one big command
                afjob_cmd = ' '.join([
                    os.environ['CGRU_PYTHONEXE'],
                    '"%s/python/afjob.py"' % os.environ['AF_ROOT'],
                    '%s' % ' '.join(tmp_cmd_buffer) % kwargs
                ])
                cmds.append(afjob_cmd)

        else:
            # create one big command
            afjob_cmd = ' '.join([
                os.environ['CGRU_PYTHONEXE'],
                '%s/python/afjob.py' % os.environ['AF_ROOT'],
                '%s' % ' '.join(cmd_buffer) % kwargs
            ])
            cmds.append(afjob_cmd)

        # call each command separately
        for cmd in cmds:
            print(cmds)

            os.system(cmd)
Esempio n. 34
0
	def importPalette(self, palName, version, binding= False, anim= False, asDelta= False, delta= []):
		"""
		** NOT SUPPORT NAMESPACE **
		XGen palette will imported without validator.
		[!!!] When importing [BAKED] palette, @binding set to False should be fine.
		"""
		xgenFileName = palName + '.xgen'
		xgenFile = str('/'.join([self.paletteVerDir(palName, version), xgenFileName]))
		if not os.path.isfile(xgenFile):
			self.notifyMsg('.xgen file is not exists.', 2)
			pm.error('[XGen Hub] : .xgen file is not exists. -> ' + xgenFile)
			return None
		if asDelta and not pm.sceneName():
			self.notifyMsg('Please save the scene.', 2)
			return None
		
		self.clearPreview()
		
		# check if palette exists in current scene
		if palName in xg.palettes():
			# delete current palette folder
			palDir = xg.expandFilepath(xg.getAttr('xgDataPath', palName), '')
			if os.path.isdir(palDir):
				try:
					dir_util.remove_tree(palDir)
				except:
					pm.warning('[XGen Hub] : Dir may not remove. -> ' + palDir)
			# delete current palette
			# this action might cry about 'None type object has no attr "previewer"'
			# when there is no xgen ui panel
			xg.deletePalette(palName)
		
		# IMPORT PALETTE
		palName = base.importPalette(xgenFile, delta, '')
		# update the palette with the current project
		xg.setAttr('xgProjectPath', str(pm.workspace(q= 1, rd= 1)), palName)
		dataPath = xg.paletteRootVar() + '/' + palName
		xg.setAttr('xgDataPath', dataPath, palName)
		# create imported palette folder
		paletteRoot = xg.expandFilepath(dataPath, '', True, True)
		# create all imported descriptions folder
		msxgApi.setupDescriptionFolder(paletteRoot, palName)
		# wrap into maya nodes
		palName = str(pm.mel.xgmWrapXGen(pal= palName, wp= binding, wlg= binding, gi= binding))
		# copy maps from source
		descNames = xg.descriptions(palName)
		msxgApi.setupImportedMap(xgenFile, palName, descNames, self.projPath)
		# bind grooming descriptions to geometry
		if binding:
			for desc in descNames:
				igdesc = xg.getAttr('groom', palName, desc)
				if igdesc:
					# get groom dag node
					igdesc = xg.igActivateDescription(desc)
					# bind groom to geo
					pm.mel.igBindFromXGen(desc)
					# set groom density and sampling method
					pm.setAttr(igdesc + '.density', 1)
					pm.setAttr(igdesc + '.interpStyle', 1)
					# set all groom visible on
					xg.igSetDescriptionVisibility(True)
					# sync primitives tab attritube map path with auto export path
					xg.igSyncMaps(desc)

			# import grooming as well
			self.importGrooming(palName)

		# import as anim, build hairSystem
		if anim:
			# build hairSystem
			self.linkHairSystem(palName)
			# check preset dir exists
			presetLocalDir = str(pm.internalVar(userPresetsDir= 1))
			presetRepo = self.nDynPresetPath(palName, version)
			if os.path.exists(presetRepo):
				# copy preset
				for prs in os.listdir(presetRepo):
					dstPath = presetLocalDir + prs
					prs = '/'.join([presetRepo, prs])
					shutil.copyfile(prs, dstPath)
				# load preset
				# [note] nucleus preset will not be loaded during current devlope
				presetMel = []
				for nodeType in ['hairSystem', 'nRigid']:
					presetDict = self.ioAttrPreset(nodeType, False)
					presetMel.extend(presetDict.values())
				# dump preset
				for prs in presetMel:
					if os.path.isfile(prs):
						os.remove(prs)
			else:
				pm.warning('[XGen Hub] : nDynamic attribute presets folder not found.')

		if asDelta:
			dataPath = xg.getAttr('xgDataPath', palName)
			dataPath = dataPath + ';' + self.paletteVerDir(palName, version, raw= True)
			xg.setAttr('xgDataPath', dataPath, palName)
			# save scenes
			pm.saveFile(f= 1)
			# set export delta
			pm.setAttr(palName + '.xgExportAsDelta', 1)

		pm.warning('[XGen Hub] : Collection Import Complete !')
		self.notifyMsg('Collection Import Complete !', 0)

		return palName
Esempio n. 35
0
def charactersDir():
    rootDir = pm.workspace(q=1, rd=1)
    charDir = rootDir + "characters/"
    pm.workspace.mkdir(charDir)
    return charDir
Esempio n. 36
0
# or instance selected objects and then randomize

# or instance selected objects, group and then randomize group

import pymel.core as pm
import maya.cmds as cmds
import random as rand

from functools import partial

import maya.mel as mel

import os

project = pm.workspace(q=True, act=True)

scriptsFilePath = project + '/scripts'

FilePath = []

nameIncrements = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
    'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
]


class EnviromentManagerWindow():
    def __init__(self):

        self.windowName = 'EnviromentManager_v001'
Esempio n. 37
0
 def submit(self):
     '''
     Main ui submit function. 
     gets global options used for all render layers, passed to each tab object.
     creates folders for muster organisation.
     '''
     if not self.mustertool:
         raise RuntimeError, "couldn't find the muster tool for submission"
     
     if not self.mustertool.checkConn(): #TODO: currently only admin user returns connection success. need to check muster setup.
         raise RuntimeError, "could not connect to muster"
     
     sceneName =  self.widgets['sceneName'].getText()
     if not sceneName:
         raise NameError, "Scene does not have a name"
     
     outputDir = self.widgets['outputDir'].getText()
     if not outputDir:
         raise NameError, "No output location specified"
     
     renderableTabs = [x for x in self.childrenTabs if x.renderable]
         
     user = self.widgets['user'].getValue()
     password = self.userPass[user]
     self.mustertool.updateUser(user, password)
     
     self.widgets['progress'].setMaxValue(len(renderableTabs) + 2) #additional two steps used for folder creation.
     self.widgets['progress'].setProgress(0)
     
     project = self.widgets['project'].getText()
     
     projectFldId = self.mustertool.checkFld(-1, project)
     if not projectFldId:
         print 'creating project folder: %s' % project
         projectFldId = self.mustertool.createFld(-1, project)
         
     self.widgets['progress'].step()
     
     sceneFldId = self.mustertool.checkFld(projectFldId, sceneName)
     if not sceneFldId:
         print 'creating project folder: %s' % sceneName
         sceneFldId = self.mustertool.createFld(projectFldId, sceneName, priority = self.widgets['priority'].getValue1())
         
     self.widgets['progress'].step()
         
     globalCmds  = ''                                                                    #Batch Submit 
     globalCmds += '-e %s ' % self.renderers[self.widgets['renderer'].getValue()]        #Engine template ID       (MANDATORY)
     globalCmds += '-pr 50 '                                                             #Priority
     globalCmds += '-pk %s ' % self.widgets['packet'].getValue1()                        #Packet
     globalCmds += '-bf %s ' % self.widgets['byFrame'].getValue1()                       #By frame                 (MAPS TO by_frame VALUE)
     globalCmds += '-st %s ' % self.widgets['byFrame'].getValue1()                       #Numbering step           (MAPS TO step_by VALUE)
     globalCmds += '-f "%s" ' % self.scene                                               #Job file                 (MAPS TO job_file VALUE)
     globalCmds += '-proj "%s" ' % pm.workspace(q = True, active = True)                 #Project path             (MAPS TO job_project VALUE)
     globalCmds += '-dest "%s" ' % outputDir                                             #Frames destination       (MAPS TO output_folder VALUE
     globalCmds += '-pool "%s" ' % self.widgets['pool'].getValue()                       #Destination Pool
     globalCmds += '-group "%s" ' % project                                              #Job Group                (formerly job project) 
     globalCmds += '-parent %s ' % sceneFldId                                            #Parent ID
     globalCmds += '-department %s ' % self.widgets['department'].getText()              #Job department
     globalCmds += '-attr MAYADIGITS %s 0 ' %self.widgets['padding'].getValue1()         #Padding
     
     if self.widgets['paused'].getValue():
         globalCmds += '-ojs 2 '                                                         #Override job status      (0 - Disabled, 1 - Idle, 2 - Paused)
         
     if self.widgets['postCopy'].getValue():
         globalCmds += '-eca "%s ' % POST_COPY_EXE                                       #Post-chunk action
         globalCmds += '%ATTR(output_folder)" '                                          #Flags added to Post-chunk action script
         globalCmds += '-ecart 0 '                                                       #Post-chunk expected return code
         
     for layer in renderableTabs:
             layer.submit(cmds = globalCmds, memoryLimit = self.widgets['memory'].getValue())
             self.widgets['progress'].step()
             
     self.widgets['progress'].setProgress(0)
Esempio n. 38
0
def constraint_parseFile(file=False,outputType=None,selected=None):
	if not file:
		filepath = os.path.basename( cmds.file(q=True, sn=True) )
		constraints_folder = os.path.join( pm.workspace( q=True, rd=True ), 'data/constraints/')
		if not os.path.exists(os.path.dirname(constraints_folder)):
			os.makedirs(os.path.dirname(constraints_folder))
		with open(pm.fileDialog2(dir=constraints_folder, cap='Select a constraints file', fm=1, fileFilter = '*.constraints')[0], 'r') as f:
			constraintFile = f.read()
		now = time.strftime("%c")
	else:
		constraintFile = open(file).read()
	sel=selected
	if selected==True:
		sel = pm.ls(sl=True)
	if selected==False:
		sel = True
	if constraintFile:
		constraints = constraintFile.split('\n')
		if outputType == 1:
			print '////////////////////////////////////////////\n//    CONSTRAINT ASSIGNMENTS\n//    %s\n//    %s\n////////////////////////////////////////////' % (filepath,now)
		if outputType == 2:
			print '############################################\n##    CONSTRAINT ASSIGNMENTS\n##    %s\n##    %s\n#############################################' % (filepath,now)
		for constraint in constraints:
			if constraint:
				type = constraint.split(':')[0]
				source = constraint.split(':')[1]
				target = constraint.split(':')[2]
				
				if outputType == None:
					if type == 'parentConstraint':
						if selected and target in sel:
							pm.parentConstraint(source, target, mo=True)
						elif not selected:
							pm.parentConstraint(source, target, mo=True)
					if type == 'scaleConstraint':
						if selected and target in sel:
							pm.scaleConstraint(source, target, mo=True)
						elif not selected:
							pm.scaleConstraint(source, target, mo=True)
					if type == 'pointConstraint':
						if selected and target in sel:
							pm.pointConstraint(source, target, mo=True)
						elif not selected:
							pm.pointConstraint(source, target, mo=True)
					if type == 'aimConstraint':
						if selected and target in sel:
							pm.aimConstraint(source, target, mo=True)
						elif not selected:
							pm.aimConstraint(source, target, mo=True)
					if type == 'orientConstraint':
						if selected and target in sel:
							pm.orientConstraint(source, target, mo=True)
						elif not selected:
							pm.orientConstraint(source, target, mo=True)
				if outputType == 1:
					print type+' -mo ' + source + ' ' + target + ';'
				if outputType == 2:
					print 'pm.'+type+'( ' + source + ', ' + target + ', mo=True )'
		if outputType == 1:
			print '/////////////////////////////////////////////\n/////////////////////////////////////////////'
		if outputType == 2:
			print '############################################\n############################################'
Esempio n. 39
0
 def getPorjPath(self):
     # get maya project
     if "maya" in self.interpreter:
         import pymel.core as pm
         return pm.workspace(q=1, dir=1)
Esempio n. 40
0
'''
Open the "movie" directory of the current project
'''

import pymel.core as pm
import webbrowser
import subprocess
import platform

movieDir = pm.workspace(q=True, rootDirectory=True) + pm.workspace.fileRules['movie']
movieDir.replace('\\', '/')

if platform.system() == 'Darwin':
    subprocess.call(['open', movieDir])  # MacOS
else:
    webbrowser.open(movieDir)  # Windows, Linux
    
Esempio n. 41
0
    def __init__(self, **kwds):

        self.character = defaultReturn('jerry', 'character', param=kwds)
        self.rigBound = defaultReturn(None, 'rigBound', param=kwds)
        self.rigVersion = defaultReturn(0, 'version', param=kwds)
        self.buildInScene = defaultReturn(0, 'buildInScene', param=kwds)

        if self.buildInScene == 0:
            pm.newFile(f=True)

        print "START: rigPuppet build " + self.character
        pm.timer(s=True)
        pm.undoInfo(state=False)
        pm.evaluationManager(mode='serial')

        try:
            self.charModule = importlib.import_module('char.' +
                                                      self.character +
                                                      'Puppet')
            print self.charModule

            pm.workspace(update=True)
            projectRoot = pm.workspace(
                q=True,
                rd=True) + 'scenes/release/rigBound/' + self.character + '/'
            print ' project root ' + projectRoot + ' found'

            if self.rigVersion == 0:
                puppetPath = pm.workspace(
                    q=True, rd=True
                ) + 'scenes/release/rigPuppet/' + self.character + '/'
                # find what is next puppet version
                puppetList = []
                os.chdir(puppetPath)
                for f in glob.glob("*.ma"):
                    puppetList.append(f)
                self.rigVersion = len(puppetList) + 1
                print 'rigVersion = ' + str(self.rigVersion)

            if self.rigBound is None:
                #projectRoot = pm.workspace(q=True, rd=True) + 'scenes/release/rigBound/'
                fileList = []
                os.chdir(projectRoot)
                for f in glob.glob("*.ma"):
                    fileList.append(f)

                fileList.sort()
                latestFile = fileList[-1:][0]
                self.rigBound = projectRoot + latestFile
                print 'latestFile = ' + latestFile
            #else:
            #   self.rigBound = projectRoot + self.rigBound + '.ma'

            if self.buildInScene == 0:
                print 'rigBound file path = ' + self.rigBound
                # import rigBound file
                try:
                    #filePath = cmds.file(self.rigBound, f=True, ignoreVersion=True,
                    # typ="mayaAscii", o=True)
                    filePath = cmds.file(self.rigBound,
                                         i=True,
                                         ignoreVersion=True,
                                         ra=False,
                                         mergeNamespacesOnClash=False,
                                         typ="mayaAscii",
                                         loadReferenceDepth='none')

                except RuntimeError:
                    print self.rigBound + ' file not found'

            cmds.dgdirty(allPlugs=True)
            cmds.refresh()

            # unparent skeleton
            rootJoint = cmds.parent(cmds.listRelatives('skeleton_GRP',
                                                       typ='joint'),
                                    w=True)[0]

            loadPose(rootJoint, 'tPose')

            pm.rename('globalOffset_GRP', 'globalOffset_GRPx')
            pm.rename('global_CTRL', 'global_CTRLx')

            self.globalCtrl = rig_control(name='global',
                                          colour='white',
                                          shape='arrows',
                                          con=0,
                                          showAttrs=['sx', 'sy', 'sz'])

            self.globalCtrl.gimbal = createCtrlGimbal(self.globalCtrl).ctrl

            self.topNode = rig_transform(0,
                                         name=self.character + 'RigPuppetTop',
                                         child=self.globalCtrl.offset).object

            topNode = pm.PyNode(self.topNode)

            pm.addAttr(topNode,
                       ln='rpAuthor',
                       at='enum',
                       enumName='JerryLee',
                       k=True)
            topNode.rpAuthor.setLocked(True)
            pm.addAttr(topNode,
                       ln='rpVersion',
                       at='enum',
                       enumName=str(self.rigVersion),
                       k=True)
            topNode.rpVersion.setLocked(True)

            topNode.translate.setLocked(True)
            topNode.rotate.setLocked(True)
            topNode.scale.setLocked(True)
            for cb in ('t', 'r', 's'):
                for at in ('x', 'y', 'z'):
                    cbAttr = getattr(topNode, cb + at)
                    cbAttr.setKeyable(False)

            try:
                self.rigGrp = pm.parent('rig_GRP', self.globalCtrl.gimbal)[0]
            except Exception as e:
                self.rigGrp = rig_transform(
                    0, name='rig', parent=self.globalCtrl.gimbal).object
                pm.addAttr(self.rigGrp,
                           longName='worldScale',
                           at='float',
                           k=True,
                           min=0,
                           defaultValue=1)
                self.rigGrp.worldScale.set(cb=True)

            try:
                self.rigModule = pm.parent('rigModules_GRP',
                                           self.globalCtrl.gimbal)[0]
            except Exception as e:
                self.rigModule = rig_transform(
                    0, name='rigModules', parent=self.globalCtrl.gimbal).object

            try:
                self.model = pm.parent('model_GRP', self.topNode)[0]
            except Exception as e:
                self.model = rig_transform(0,
                                           name='model',
                                           parent=self.topNode).object

            try:
                self.rigModel = pm.parent('rigModel_GRP', self.model)[0]
            except Exception as e:
                self.rigModel = rig_transform(0,
                                              name='rigModel',
                                              parent=self.model).object

            self.worldSpace = rig_transform(
                0, name='worldSpace', parent=self.globalCtrl.gimbal).object

            try:
                pm.delete("|*RigBoundTop_GRP")
            except pm.MayaNodeError:
                print 'RigBound top node does not exist'

            # create attributes on global ctrl
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='puppetSettings',
                       at='enum',
                       enumName='___________',
                       k=True)
            self.globalCtrl.ctrl.puppetSettings.setLocked(True)

            # model and skeleton vis
            # model
            connectAttrToVisObj(self.globalCtrl.ctrl,
                                'modelVis',
                                self.model,
                                defaultValue=1)
            # skeleton
            pm.addAttr(self.globalCtrl.ctrl,
                       longName='skeletonVis',
                       at='long',
                       k=True,
                       min=0,
                       max=1,
                       defaultValue=0)
            self.globalCtrl.ctrl.skeletonVis.set(cb=True)
            # controls
            pm.addAttr(self.globalCtrl.ctrl,
                       longName='controlsVis',
                       at='long',
                       k=True,
                       min=0,
                       max=1,
                       defaultValue=1)
            self.globalCtrl.ctrl.controlsVis.set(cb=True)

            # referencing and selecting
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='model',
                       at='enum',
                       enumName='Selectable:Reference',
                       k=True,
                       defaultValue=1)
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='skeleton',
                       at='enum',
                       enumName='Selectable:Reference',
                       k=True,
                       defaultValue=1)

            # LOD vis
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='lodSetting',
                       at='enum',
                       enumName='___________',
                       k=True)
            self.globalCtrl.ctrl.lodSetting.setLocked(True)
            pm.addAttr(self.globalCtrl.ctrl,
                       ln='lodDisplay',
                       at='enum',
                       enumName='Low:Mid:High',
                       k=True,
                       defaultValue=0)

            lodModel = [
                'lowLOD_GRP', 'lowMidLOD_GRP', 'midLOD_GRP', 'midHighLOD_GRP',
                'highLOD_GRP'
            ]

            for lod in lodModel:
                if pm.objExists(lod):
                    lodGRP = pm.PyNode(lod)
                    if 'low' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=0)
                    if 'mid' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=0)
                    if 'high' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=1)
                    if 'lowMid' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=0)
                    if 'midHigh' in lod:
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=0,
                            v=0)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=1,
                            v=1)
                        pm.setDrivenKeyframe(
                            lodGRP.visibility,
                            cd=self.globalCtrl.ctrl.lodDisplay,
                            dv=2,
                            v=1)

            if cmds.objExists('allModel_GRP'):
                cmds.setAttr("allModel_GRP.visibility", 1)

            # scale global control
            self.bbox = self.model.boundingBox()
            width = self.bbox.width() * 0.3
            cvsGlobal = pm.PyNode(self.globalCtrl.ctrl + '.cv[:]')
            cvsGimbal = pm.PyNode(self.globalCtrl.gimbal + '.cv[:]')
            pm.scale(cvsGlobal, width, width, width)
            pm.scale(cvsGimbal, width / 1.5, width / 1.5, width / 1.5)

            # make display toggle
            self.displayTransform = pm.circle(
                name='displayModulesToggleControl', sw=360, nr=(0, 1, 0),
                ch=0)[0]
            pm.delete(self.displayTransform.getShape())

            displayCurves = pm.PyNode(
                pm.textCurves(f="Quartz|wt:50|sz:28|sl:n|st:100",
                              t="Display",
                              ch=0,
                              fzn=True)[0])
            pm.setAttr(displayCurves.translateX, -1.7)
            pm.move(0, 0, 0, displayCurves.rotatePivot, p=True, ws=True)
            pm.move(0, 0, 0, displayCurves.scalePivot, p=True, ws=True)

            pm.move(0, (self.bbox.height() + (self.bbox.height() * 0.1)),
                    0,
                    displayCurves,
                    r=True)
            displayScale = self.bbox[1][0] / 4
            pm.scale(displayCurves, displayScale, displayScale, displayScale)

            allCurves = pm.listRelatives(displayCurves,
                                         ad=True,
                                         c=True,
                                         type="nurbsCurve")
            parentCurves = []
            for crv in allCurves:
                parentTransform = pm.listRelatives(crv, p=True)[0]
                pm.parent(parentTransform, w=True)
                pm.makeIdentity(parentTransform, apply=True, t=1, r=1, s=1)
                pm.parent(crv, self.displayTransform, shape=True, add=True)
                parentCurves.append(parentTransform)

            pm.dgdirty(allPlugs=True)
            pm.refresh()
            pm.delete(parentCurves, s=False)
            pm.delete(displayCurves)
            pm.parent(self.displayTransform, self.globalCtrl.ctrl)
            for at in [
                    'translateX', 'translateY', 'translateZ', 'rotateX',
                    'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ',
                    'visibility'
            ]:
                #getattr(self.displayTransform, at).set(k=False)
                self.displayTransform.attr(at).set(k=False)
                self.displayTransform.attr(at).setLocked(True)

            pm.connectAttr(self.globalCtrl.ctrl + '.scaleX',
                           self.rigGrp.worldScale)
            pm.hide(self.rigGrp, self.rigModel)

            pm.addAttr(self.globalCtrl.ctrl,
                       ln='rigAuthor',
                       at='enum',
                       enumName='Jerry:Lee',
                       k=False,
                       dv=0)

            self.prepareRig()

            self.createRigModules()

            self.finishRig()

            pm.select(cl=True)

            #self.sup = super(puppet, self)
            #self.sup.__init__(self.topNode, **kwds)

        except Exception as e:
            print "*************************************"
            print "=========== Error happened ========="
            raise
        finally:
            pm.evaluationManager(mode='parallel')

            mayaTimer = pm.timer(e=True)

            pm.undoInfo(state=True)
            print ''
            print ''
            print "END: rigPuppet built in %g seconds" % mayaTimer
            print ''
from mtoa.cmds.arnoldRender import arnoldRender
import maya.cmds as cmds
import mtoa.aovs as aovs
import pymel.core as pm

#declare target render dir
render_dir = r'C:\Users\12213119\Documents\temp'

#define workspace file rule for images
pm.workspace(fileRule=['images', render_dir])

# ---------------------------------------------------------
# Render Image
# ---------------------------------------------------------

# Set AOVs
aovs.AOVInterface().addAOV('beauty')
aovs.AOVInterface().addAOV('specular')
aovs.AOVInterface().addAOV('N')

# Set Sampeling
cmds.setAttr("defaultArnoldRenderOptions.AASamples", 1)  # set Camera Sample
cmds.setAttr("defaultArnoldRenderOptions.GIDiffuseSamples",
             1)  # set Diffuse Sample
cmds.setAttr("defaultArnoldRenderOptions.GISpecularSamples",
             1)  # set Specular Sample
cmds.setAttr("defaultArnoldRenderOptions.GITransmissionSamples",
             1)  # set Trasmission
cmds.setAttr("defaultArnoldRenderOptions.GISssSamples", 1)  # set SSS
cmds.setAttr("defaultArnoldRenderOptions.GIVolumeSamples",
             1)  # set Volume Indirect
Esempio n. 43
0
def getCurrentProject():
    """ Returns the last set Project Directory """
    return pm.workspace(q=True, rootDirectory=True)
Esempio n. 44
0
def getSceneData(jobtype, *a ):
    """Gathers scene information and executes the shell command to open a Qube submission window"""
    rg = pm.PyNode('defaultRenderGlobals')

    # GET MAYA VERSION
    if jobtype == 'mayacmd':
        if versions.current()/100 == 2013:
            render_exe = "R:/Program Files/Autodesk/Maya2013/bin/Render.exe"
        if versions.current()/100 == 2015:
            render_exe = "R:/Program Files/Autodesk/Maya2015/bin/Render.exe"
    
    elif jobtype == 'mayapy':
        if versions.current()/100 == 2013:
            render_exe = "R:/Program Files/Autodesk/Maya2013/bin/mayabatch.exe"
        if versions.current()/100 == 2015:
            render_exe = "R:/Program Files/Autodesk/Maya2015/bin/mayabatch.exe"

    # Populate base scene information
    scene_file_path = pathFormat(pm.system.sceneName())
    project_path    = pathFormat(pm.workspace(q=True, rd=True).replace('/','\\'))
    image_path      = pathFormat(os.path.join(project_path, pm.workspace('images', q=True, fre=True)).replace('/','\\'))
    frame_range     = str(int(rg.startFrame.get())) + "-" + str(int(rg.endFrame.get()))
    scene_cameras   = ','.join(getSceneUserCameras())
    renderer        = rg.ren.get()
    render_layers   = ','.join([str(layer) for layer in pm.ls(type='renderLayer') if not 'defaultRenderLayer' in str(layer)])
    layer_name      = str(pm.editRenderLayerGlobals(q=True, crl=True))

    submit_dict = {
        'name': 'maya(cmd) ' + pm.sceneName().basename().rstrip('.mb'),
        'prototype':'cmdrange',
        'package':{
            'simpleCmdType': 'Maya BatchRender (vray)',
            'scenefile': scene_file_path,
            '-r': 'vray',
            '-proj': project_path, 
            'range': frame_range,
            '-rl': layer_name,
            '-rd': '',
            '-threads': default_threads,
            'mayaExe': render_exe,
            'rangeExecution': 'chunks:' + str(default_chunk)
            },
        'cluster': '/',
        'restrictions': '',
        'requirements': '',
        'priority': default_priority,
        'cpus': default_maxcpu,
        'reservations': 'host.processors=' + str(default_threads),
        'flagsstring': 'auto_wrangling,disable_windows_job_object'
        }

    submit_dict_mayapy = {
        'name': 'maya(py) ' + pm.sceneName().basename().rstrip('.mb'),
        'prototype':'maya',
        'package':{
            'scenefile': scene_file_path.replace('/','\\'),
            'project': project_path, 
            'range': frame_range, 
            'cameras_all': scene_cameras, 
            'layers_all': render_layers,
            'layers': layer_name,
            'mayaExecutable': render_exe,
            'renderDirectory': image_path,
            'renderThreads': 0,
            'renderThreadCount': 1,
            'ignoreRenderTimeErrors': True,
            'useAllCores': 1
            },
     'cluster': '/',
     'restrictions': '',
     'requirements': '',
     'priority': default_priority,
     'cpus': default_maxcpu,
     'reservations': 'host.processors=1+',
     'requirements': 'host.processors.used==0',
     'flagsstring': 'auto_wrangling,disable_windows_job_object'
    }
    '''
    # SANITY CHECKS
    # 1- scene never saved
    if scene_file_path == '':
        pm.confirmDialog( title='Scene not saved.',
                          button='Whoops',
                          message='Please save scene on cagenas before submitting.',
                          defaultButton='Whoops'
                          )
        return 'sanity check fail'

    # 2- no user cameras in scene
    if scene_cameras == None:
        pm.confirmDialog( title='No renderable camera.',
                          button='Whoops',
                          message='No renderable cameras found in your scene.',
                          defaultButton='Whoops'
                          )
        return 'sanity check fail'

    elif len(scene_cameras) > 1:
        confirm = pm.confirmDialog( title='Multiple renderable cameras.',
                          button=('Whoops', 'That\'s fine'),
                          cancelButton='That\'s fine',
                          message='You have multiple renderable cameras in your scene.  All of them will be rendered.  Proceed?',
                          defaultButton='Whoops',
                          dismissString='That\'s fine'
                          )
        if confirm == 'That\'s fine':
            pass
        elif confirm == 'Whoops':
            return 'sanity check fail'

    # 3- animation rendering not enabled
    if rg.animation.get() == False:
        check = pm.confirmDialog( title='Animation not enabled.',
                                  button=('Whoops', 'That\'s fine'),
                                  cancelButton='That\'s fine',
                                  message='Animation is not enabled in your render globals.',
                                  defaultButton='Whoops',
                                  dismissString='That\'s fine'
                                  )
        print check
        if check == 'Whoops':
            return 'sanity check fail'
        else: pass

    # 4- framerate weirdness
    if (rg.endFrame.get() % int(rg.endFrame.get())):
        pm.confirmDialog( title='Framge range is strange!',
                          button='Whoops',
                          message='Animation frame range is wonky.  Did you change framerate?',
                          defaultButton='Whoops'
                          )
        return 'sanity check fail'        
    '''
    if jobtype == 'mayacmd':
        return submit_dict
    elif jobtype == 'mayapy':
        return submit_dict_mayapy
Esempio n. 45
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')

        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name, file_full_path=filename,
            render_engine=render_engine, project=project_path,
            by_frame=by_frame
        )

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0], outputs[1])
                        )
                    ).split(';')
                )
                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 46
0
    mc.rename(item,new_name+str(idx +1).zfill(4)) #新名字添加序列从1开始,.zfill(4)4位0001


mc.rename('item_####_grp',mc.ls(ls=True),10) #''命名格式,选择的物体,起始数字(待确认)

s=['S3_E11_Sc06_Cam003_Cam_s823e851.fbx']
''.join(s) #Result: S3_E11_Sc06_Cam003_Cam_s823e851.fbx

f='S:\QSJResources\Shot\GodGunStory\S3_E11\\'
f.replace('\\', '/') #Result: S:/QSJResources/Shot/GodGunStory/S3_E11/


allCam = mc.ls(long = True,type = "camera") #列出所有摄像机
allCam.sort(key=len, reverse=True) #按名称长度排列
renderCam = allCam[0].split('|')[1] #字符串按照|拆分开,并取第二位
renderCam2=''.join(renderCam) #连接每个字符串''中指定以什么方式连接(-,:,|)等

children = mc.listRelatives(obj,children=True, fullPath=True) or [] #获得物体的shape节点

maya_renderer = "%s/bin/Render.exe" % os.getenv("MAYA_LOCATION").replace('\\', '/')
#Result: C:/Program Files/Autodesk/Maya2016/bin/Render.exe

mc.internalVar(userAppDir=True)
# Result: u'C:/Users/Administrator/Documents/maya/'

pm.workspace.getcwd() #新
pm.workspace(query=1, dir=1) #老
# 获取当前文件所在目录,maya中会返回 Result: Path('D:/') ,转成str()可以去除u,Path等字符

mc.file(q=True, sn=1, shn=1) #获取当前maya的文件名
Esempio n. 47
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [(attr, dAO.getAttr(attr)) for attr in ignore_attrs
                           if dAO.getAttr(attr) is True]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x: '%s: %s' % (x[0], x[1]), attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok')
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        job_name = os.path.basename(scene_name)

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')

        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(name=job_name,
                                       file_full_path=filename,
                                       render_engine=render_engine,
                                       project=project_path,
                                       by_frame=by_frame)

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections() if layer.renderable.get()
            ]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya'))

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0],
                                                      outputs[1]))).split(';'))
                block.setNumeric(start_frame, end_frame, frames_per_task,
                                 by_frame)
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block('All Layers',
                             renderer_to_block_type.get(render_engine, 'maya'))

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0],
                                                  outputs[1]))).split(';'))
            block.setNumeric(start_frame, end_frame, frames_per_task, by_frame)
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 48
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title="Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message='It is not allowed to render with the following option is enabled:<br>'
                            '<br>'
                            "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                            "<br>"
                            "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')


            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            glossy_samples = dAO.GIGlossySamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 450

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Diffuse '
                            'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Glossy '
                            'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of SSS '
                            'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get() < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                            '<br>'
                            'on <b>Point lights with zero radius</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                            '<br>'
                            '<b>Area Lights</b><br>'
                            '<br>'
                            'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get() == 0 and directional_light.aiSample.get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                            '<br>'
                            '<b>Directional lights with zero angle</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.checkBox('cgru_afanasy__separate_layers', q=1, v=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        outputs = \
            pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene        = %s' % scene_name)
        logger.debug('file         = %s' % filename)
        logger.debug('job_name     = %s' % job_name)
        logger.debug('project_path = %s' % project_path)
        logger.debug('outputs      = %s' % outputs)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)



        job = af.Job(job_name)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 1)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name, file_full_path=filename,
            render_engine=render_engine, project=project_path,
            by_frame=by_frame
        )

        # submit renders
        blocks = []
        if separate_layers:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0], outputs[1])
                        )
                    ).split(';')
                )
                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                block.setCommand(mrc_layer.build_command())

                blocks.append(block)
        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            block.setCommand(mrc.build_command())

            blocks.append(block)

        job.setFolder('input', os.path.dirname(filename))
        job.setFolder('output', os.path.dirname(outputs[0]))
        job.setHostsMask(hosts_mask)
        job.setHostsMaskExclude(hosts_exclude)
        if life_time > 0:
            job.setTimeLife(life_time * 3600)

        job.setCmdPost('deletefiles "%s"' % os.path.abspath(filename))
        if pause:
            job.offline()

        # add blocks
        job.blocks.extend(blocks)

        status, data = job.send()
        if not status:
            pm.PopupError('Something went wrong!')
        print('data: %s' % data)

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)
Esempio n. 49
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision', 'ignoreDisplacement', 'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [(attr, dAO.getAttr(attr)) for attr in ignore_attrs
                           if dAO.getAttr(attr) is True]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(lambda x: '%s: %s' % (x[0], x[1]), attr_values))

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message=
                    'You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' %
                    msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
        except (pm.MayaNodeError, pm.MayaAttributeError):
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',
                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [
                node for node in pm.ls(type='camera')
                if node.getAttr('renderable')
            ]
            if any(
                    map(lambda x: x.name() in wrong_camera_names,
                        renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message=
                    'You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message=
                    'You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok')
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title=
                    "Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message=
                    'It is not allowed to render with the following option is enabled:<br>'
                    '<br>'
                    "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                    "<br>"
                    "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check dome light backgrounds
            domes_to_fix = []
            rs_domes = pm.ls(type='RedshiftDomeLight')
            if rs_domes:
                for rs_dome in rs_domes:
                    if rs_dome.getAttr('background_enable') == 1 \
                       or rs_dome.getAttr('backPlateEnabled') == 1:
                        domes_to_fix.append(rs_dome.name())

            if domes_to_fix:
                message = 'Some DomeLights have <b>BackGround Render ' \
                          'Enabled</b>:' \
                          '<br><br>%s<br><br>' \
                          'Are you Sure?' % '<br>'.join(domes_to_fix)

                response = pm.confirmDialog(
                    title='Dome Lights with Background Enabled?',
                    message=message,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No')
                if response == 'No':
                    return

            # abort on license fail
            dro.abortOnLicenseFail.set(1)

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            try:
                glossy_samples = dAO.GIGlossySamples.get()
            except AttributeError:
                glossy_samples = dAO.GISpecularSamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 800

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of Diffuse '
                    'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of Glossy '
                    'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                    '<br>'
                    'Please either reduce AA samples of SSS '
                    'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get(
                ) < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                    '<br>'
                    'on <b>Point lights with zero radius</b><br>'
                    '<br>'
                    'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                    '<br>'
                    '<b>Area Lights</b><br>'
                    '<br>'
                    'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            dir_sample_attr_name = 'aiSamples'
            # if pm.about(v=1) == "2014":
            #     dir_sample_attr_name = 'aiSamples'

            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get(
                ) == 0 and directional_light.attr(
                        dir_sample_attr_name).get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                    '<br>'
                    '<b>Directional lights with zero angle</b><br>'
                    '<br>'
                    'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK')
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        depend_mask_global = pm.textField('cgru_afanasy__depend_mask_global',
                                          q=1,
                                          text=True)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude',
                                     q=1,
                                     text=True)
        separate_layers = \
            pm.radioButtonGrp('cgru_afanasy__separate_layers', q=1, sl=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)
        annotation = pm.textField('cgru_afanasy__annotation', q=1, text=True)
        submit_multiple_times = pm.intField(
            'cgru_afanasy__submit_multiple_times', q=1, v=1)
        errors_avoid_host = pm.intField('cgru_afanasy__errors_avoid_host',
                                        q=1,
                                        v=1)
        errors_retries = pm.intField('cgru_afanasy__errors_retries', q=1, v=1)
        errors_task_same_host = pm.intField(
            'cgru_afanasy__errors_task_same_host', q=1, v=1)
        errors_forgive_time = pm.intField('cgru_afanasy__errors_forgive_time',
                                          q=1,
                                          v=1)

        generate_previews = pm.checkBox('cgru_afanasy__generate_previews',
                                        q=1,
                                        v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        depend_mask_global = depend_mask_global.replace('"', '')
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__depend_mask_global_ov'] = \
            depend_mask_global
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time
        pm.optionVar['cgru_afanasy__annotation_ov'] = annotation

        pm.optionVar[
            'cgru_afanasy__submit_multiple_times_ov'] = submit_multiple_times
        pm.optionVar['cgru_afanasy__errors_avoid_host_ov'] = errors_avoid_host
        pm.optionVar['cgru_afanasy__errors_retries_ov'] = errors_retries
        pm.optionVar[
            'cgru_afanasy__errors_task_same_host_ov'] = errors_task_same_host
        pm.optionVar[
            'cgru_afanasy__errors_errors_forgive_time_ov'] = errors_forgive_time
        pm.optionVar['cgru_afanasy__paused_ov'] = pause

        pm.optionVar['cgru_afanasy__generate_previews_ov'] = generate_previews

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (time.strftime('%y%m%d-%H%M%S-'),
                             str(time.time() - int(time.time()))[2:5])

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # outputs = \
        #     pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene                 = %s' % scene_name)
        logger.debug('file                  = %s' % filename)
        logger.debug('job_name              = %s' % job_name)
        logger.debug('project_path          = %s' % project_path)
        logger.debug('outputs               = %s' % outputs)
        logger.debug('annotation            = %s' % annotation)
        logger.debug('separate_layers       = %s' % separate_layers)
        logger.debug('errors_avoid_host     = %s' % errors_avoid_host)
        logger.debug('errors_retries        = %s' % errors_retries)
        logger.debug('errors_task_same_host = %s' % errors_task_same_host)
        logger.debug('errors_forgive_time   = %s' % errors_forgive_time)
        logger.debug('generate_previews     = %s' % generate_previews)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 2)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(filename, force=1, type='mayaBinary')

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(name=job_name,
                                       file_full_path=filename,
                                       render_engine=render_engine,
                                       project=project_path,
                                       by_frame=by_frame)

        # submit renders
        jobs = []
        blocks = []

        #
        # separate_layers:
        # 1 -> None  -> submit one job with a single block with all layers
        # 2 -> Block -> submit one job with multiple blocks
        # 3 -> Job   -> submit multiple jobs with a single block per layer
        #
        if separate_layers in [1, 2]:
            job = af.Job(job_name)
            jobs.append(job)

        if separate_layers in [2, 3]:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [
                layer for layer in rlm.connections(type=pm.nt.RenderLayer)
                if layer.renderable.get()
            ]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya'))

                # Fix the output path for this layer
                # by replacing the "masterLayer" with the layer name
                # without rs_ at the beginning
                layer_outputs = outputs
                if layer_name != 'defaultRenderLayer':
                    layer_outputs[0] = outputs[0].replace(
                        'masterLayer', layer_name.replace('rs_', ''))
                    layer_outputs[1] = outputs[1].replace(
                        'masterLayer', layer_name.replace('rs_', ''))

                if generate_previews:
                    outputs_split = afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(
                                layer_outputs[0],
                                layer_outputs[1]))).split(';')
                    block.setFiles(outputs_split)

                block.setNumeric(start_frame, end_frame, frames_per_task,
                                 by_frame)
                command = mrc_layer.build_command()

                block.setErrorsAvoidHost(errors_avoid_host)
                block.setErrorsRetries(errors_retries)
                block.setErrorsTaskSameHost(errors_task_same_host)
                block.setErrorsForgiveTime(errors_forgive_time)

                block.setCommand(command)

                if separate_layers == 2:
                    blocks.append(block)
                else:
                    job = af.Job('%s - %s' % (job_name, layer_name))
                    # add blocks
                    job.blocks = [block]
                    jobs.append(job)

        else:
            # create only one block
            block = af.Block('All Layers',
                             renderer_to_block_type.get(render_engine, 'maya'))

            if generate_previews:
                block.setFiles(
                    afcommon.patternFromDigits(
                        afcommon.patternFromStdC(
                            afcommon.patternFromPaths(outputs[0],
                                                      outputs[1]))).split(';'))

            block.setNumeric(start_frame, end_frame, frames_per_task, by_frame)
            command = mrc.build_command()
            block.setCommand(command)

            blocks.append(block)

        for job in jobs:
            job.setAnnotation(annotation)
            job.setFolder('input', os.path.dirname(filename))
            job.setFolder('output', os.path.dirname(outputs[0]))
            job.setDependMaskGlobal(depend_mask_global)
            job.setHostsMask(hosts_mask)
            job.setHostsMaskExclude(hosts_exclude)
            if life_time > 0:
                job.setTimeLife(life_time * 3600)
            else:
                job.setTimeLife(240 * 3600)

            job.setCmdPost('deletefiles -s "%s"' % os.path.abspath(filename))
            if pause:
                job.offline()

            # add blocks
            if separate_layers in [1, 2]:
                job.blocks.extend(blocks)

            for i in range(submit_multiple_times):
                orig_job_name = job.data['name']
                job.setName('%s - %03i' % (orig_job_name, i + 1))
                status, data = job.send()

                # restore job name
                job.setName(orig_job_name)
                if not status:
                    pm.PopupError('Something went wrong!')

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)

            # disable abort on license fail
            redshift.abortOnLicenseFail.set(0)
Esempio n. 50
0
def exportSkin(filePath=None, objs=None, *args):
    if not objs:
        if pm.selected():
            objs = pm.selected()
        else:
            pm.displayWarning("Please Select One or more objects")
            return False

    packDic = {"objs": [], "objDDic": [], "bypassObj": []}

    if not filePath:

        f2 = "jSkin ASCII  (*{});;gSkin Binary (*{})".format(
            FILE_JSON_EXT, FILE_EXT)
        f3 = ";;All Files (*.*)"
        fileFilters = f2 + f3
        startDir = pm.workspace(q=True, rootDirectory=True)
        filePath = pm.fileDialog2(dialogStyle=2,
                                  fileMode=0,
                                  startingDirectory=startDir,
                                  fileFilter=fileFilters)
        if filePath:
            filePath = filePath[0]

        else:
            return False

    if (not filePath.endswith(FILE_EXT)
            and not filePath.endswith(FILE_JSON_EXT)):
        # filePath += file_ext
        pm.displayWarning("Not valid file extension for: {}".format(filePath))
        return

    _, file_ext = os.path.splitext(filePath)
    # object parsing
    for obj in objs:
        skinCls = getSkinCluster(obj)
        if not skinCls:
            pm.displayWarning(obj.name() +
                              ": Skipped because don't have Skin Cluster")
            pass
        else:
            #start by pruning by a tiny amount. Enough to not make a noticeable
            #change to the skin, but it will remove infinitely small weights.
            #Otherwise, compressing will do almost nothing!
            if isinstance(obj.getShape(), pm.nodetypes.Mesh):
                #TODO: Implement pruning on nurbs. Less straight-forward
                pm.skinPercent(skinCls, obj, pruneWeights=0.001)

            dataDic = {
                'weights': {},
                'blendWeights': [],
                'skinClsName': "",
                'objName': "",
                'nameSpace': "",
                'vertexCount': 0,
                'skinDataFormat': 'compressed',
            }

            dataDic["objName"] = obj.name()
            dataDic["nameSpace"] = obj.namespace()

            collectData(skinCls, dataDic)

            packDic["objs"].append(obj.name())
            packDic["objDDic"].append(dataDic)
            exportMsg = "Exported skinCluster {} ({} influences, {} points) {}"
            pm.displayInfo(
                exportMsg.format(skinCls.name(),
                                 len(dataDic['weights'].keys()),
                                 len(dataDic['blendWeights']), obj.name()))

    if packDic["objs"]:
        with open(filePath, 'w') as fp:
            if filePath.endswith(FILE_EXT):
                pickle.dump(packDic, fp, pickle.HIGHEST_PROTOCOL)
            else:
                json.dump(packDic, fp, indent=4, sort_keys=True)

        return True
Esempio n. 51
0
 def getScenePath(self):
     return ( pm.workspace( q=True, rd=True ) + pm.workspace( 'scene', q=True, fileRuleEntry=True ) ).replace('/','\\')
Esempio n. 52
0
def playblast_publish():
    answer = pm.confirmDialog(
        title="Publish playblasted movies",
        message=
        "Copy all files in playblasts folder to corresponding subfolders?",
        button=["OK", "Cancel"],
        defaultButton="OK",
        cancelButton="Cancel",
        dismissString="Cancel")

    if answer == "Cancel":
        return

    # move to movie folder in current maya project
    movie_dir = pm.workspace(
        q=True, rootDirectory=True) + pm.workspace.fileRules['movie']
    movie_dir.replace('\\', '/')
    playblast_dir = movie_dir + "/playblasts"

    os.chdir(playblast_dir)

    # get all mov files in movie directory
    source_files = []

    for f in glob.glob("*.mov"):
        source_files.append(f)

    source_files = sorted(source_files)

    # create subfolder based on file name
    prog = re.compile("([A-Za-z0-9])*")
    errors = []

    for f in source_files:
        base = os.path.splitext(f)[0]

        # create folder for file
        result = prog.match(base)
        pub_dir = movie_dir + "/" + result.group(0)

        if not os.path.exists(pub_dir):
            os.makedirs(pub_dir)

        pub_file = ("%s/%s") % (pub_dir, f)
        playblast_file = ("%s/%s") % (playblast_dir, f)

        is_newer = os.path.getmtime(playblast_file) > os.path.getmtime(
            pub_file)

        # create version in _archive and playblast file is newer
        if os.path.exists(pub_file) and is_newer:
            archive_dir = pub_dir + "/_archive"
            if not os.path.exists(archive_dir):
                os.makedirs(archive_dir)

            version = 1
            version_path = ""

            while (True):
                version_path = ("%s/_archive/%s_v%03d.mov") % (pub_dir, base,
                                                               version)
                if not os.path.exists(version_path):
                    break
                version = version + 1

            copyfile(pub_file, version_path)

        # copy from movie_dir to subfolder if newer

        if is_newer:
            try:
                copyfile(playblast_file, pub_file)
            except:
                errors.append(pub_file)
            print("# Copied %s" % (playblast_file))
            print("# --> %s" % (pub_file))

    if errors:
        print('\n\n# Failed to copy to the following files:')
        for error in errors:
            print('# %s' % (error))
        pm.warning(
            'Some files were not copied! See script editor for details.')
    else:
        sys.stdout.write('\n\n# Successfully copied all files!\n')
class Coat:
    #class variables
    project_dir = pm.workspace(q=True, rd=True)
    need_opacity_map = False
    need_bump_map = False
    bump_is_normal = False  #bump is height map by default

    def __init__(self, blend_material, coat_number, size):
        self.parent_blend_material = blend_material
        self.coat_number = coat_number
        self.colorQImage = QtGui.QImage(
            size, size, QtGui.QImage.Format_RGB32)  #stores color map
        self.bumpQImage = QtGui.QImage(
            size, size, QtGui.QImage.Format_RGB32)  #stores bump map
        self.opacityQImage = QtGui.QImage(
            size, size, QtGui.QImage.Format_RGB32)  #stores opacity map
        if (coat_number != None):
            #regular coat
            self.material = pm.listConnections(blend_material +
                                               ".coat_material_" +
                                               str(coat_number))
            self.matteQImage = QtGui.QImage(
                size, size, QtGui.QImage.Format_RGB32)  #stores matte map
        else:
            #base coat
            self.material = pm.listConnections(blend_material.base_material)
        self.isTransparent = False  #keeps track if coat material is transparent
        self.hasBump = False  #keeps track if coat material has bump

    def get_material(self):
        return self.material

    def get_colorQImage(self):
        return self.colorQImage

    def set_colorQImage(self, qImage):
        self.colorQImage = qImage

    def get_opacityQImage(self):
        return self.opacityQImage

    def set_opacityQImage(self, qImage):
        self.opacityQImage = qImage

    def get_bumpQImage(self):
        return self.bumpQImage

    def set_bumpQImage(self, qImage):
        self.bumpQImage = qImage

    def get_matteQImage(self):
        return self.matteQImage

    def set_matteQImage(self, qImage):
        self.matteQImage = qImage

    def get_isTransparent(self):
        return self.isTransparent

    def set_isTransparent(self, is_transparent):
        self.isTransparent = is_transparent

    def get_hasBump(self):
        return self.hasBump

    def set_hasBump(self, has_bump):
        self.hasBump = has_bump

    def set_bumpIsNormal(self, bump_is_normal):
        Coat.bump_is_normal = bump_is_normal

    def set_need_opacity_map(self, need_opacity_map):
        Coat.need_opacity_map = need_opacity_map

    def set_need_bump_map(self, need_bump_map):
        Coat.need_bump_map = need_bump_map
def run():
    if not pm.ls('cam_focus_*'):
        pm.warning(u'没有可以导出的相机')
        return

    if pm.ls(type='unknown'):
        pm.delete(pm.ls(type='unknown'))
    if pm.ls('shaveGlobals'):
        pm.lockNode(pm.ls('shaveGlobals'), l=False)
        pm.delete(pm.ls('shaveGlobals'))

    path_obj = pft.PathDetails.parse_path(pm.sceneName())
    pubfile = path_obj.getNewVersionForTask('cam-focus', publish=True)
    if not path_obj.user:
        pm.warning(u'请检查本场景文件的路径,特别注意下文件名本身')
        return
    os.makedirs(os.path.dirname(pubfile))

    # --------------------------------------------------------------------------------------------------------
    # 序列帧输出
    # projectdir = pm.Workspace.getPath()
    # imagedir = os.path.join(projectdir, 'images/focus')

    images_in_project = pm.workspace(
        en=pm.workspace('images', q=True, fre=True))
    imagedir = os.path.join(images_in_project, 'focus')

    # os.makedirs(os.path.join(os.path.dirname(pubfile), 'images'))
    # pm.sysFile(imagedir, copy=os.path.join(os.path.dirname(pubfile), 'images'))
    shutil.copytree(imagedir,
                    os.path.join(os.path.dirname(pubfile), 'images/focus'))
    # --------------------------------------------------------------------------------------------------------
    # 相机输出
    cams = map(
        lambda x: x.getParent(),
        filter(lambda x: x.name().startswith('cam_focus_'),
               pm.ls(type='camera')))
    pm.select(cams, r=True)
    camsFile = os.path.splitext(pubfile)[0] + '.ma'
    pm.exportSelected(camsFile, force=True)
    # --------------------------------------------------------------------------------------------------------
    # 生成缩略图
    mmfpeg = 'ffmpeg.exe'
    seqfile = os.path.normpath(
        os.path.join(os.path.dirname(pubfile), 'images/focus/focus.%04d.exr'))
    movfile = os.path.join(
        os.path.dirname(pubfile),
        '{}.mov'.format(os.path.basename(pubfile).split('.')[0]))
    beginframe, endframe = psg.get_cut_range(
        path_obj.project, '%s_%s' % (path_obj.seq, path_obj.shot))
    framenum = endframe - beginframe + 2
    # 这里有个bug在ffmpeg里
    convertcmd = '{} -apply_trc iec61966_2_1 -start_number 1001 -f image2 -r 24 -i {} -vcodec h264 -vframes {} -preset veryslow -qp 0 {}'.format(
        mmfpeg, seqfile, framenum, movfile)

    p = subprocess.Popen(convertcmd, shell=True, cwd=os.path.dirname(__file__))
    p.wait()
    # -----------------------------------------------------------------------------------
    # 上传shotgun
    versionID = psg.addToShotgun(camsFile, '')
    if versionID:
        psg.uploadQuicktime(versionID, movfile)
    # --------------------------------------------------------------------------------------------------------
    # 输出制作文件
    animSourceFile = os.path.join(
        os.path.dirname(pubfile),
        os.path.basename(pm.sceneName()).replace("anim", 'focus'))
    pm.saveAs(animSourceFile)

    # --------------------------------------------------------------------------------------------------------
    # 打开publish目录
    pm.warning(u'导出CamFocus相机完成,文件另存为完成,序列帧复制完成')
    os.startfile(os.path.dirname(pubfile))
Esempio n. 55
0
            res = cb(path, tokens, **kwargs)
        except Exception, err:
            if catchErrors:
                print "Callback %s.%s failed: %s" % (cb.__module__, cb.__name__, err)
            else:
                raise
        else:
            if res is not None:
                path = res

    #print path, tokens
    partialPath = expandFileTokens(path, tokens, leaveUnmatchedTokens=leaveUnmatchedTokens)
    if pathType in [pm.api.MCommonRenderSettingsData.kRelativePath, 'relative']:
        return partialPath

    imageDir = pm.workspace(fileType, q=True, fileRuleEntry=True)
    imageDir = imageDir if imageDir else 'data'
    imageDir = pm.workspace(expandName=imageDir);

    if pathType in [pm.api.MCommonRenderSettingsData.kFullPathTmp, 'temp']:
        result = os.path.join(imageDir, 'tmp', partialPath)
    elif pathType in [pm.api.MCommonRenderSettingsData.kFullPathImage, 'full']:
        result = os.path.join(imageDir, partialPath)
    else:
        raise TypeError("Invalid pathType")

    result = result.replace("\\", "/")
    if createDirectory:
        dir =  os.path.dirname(result)
        try:
            os.makedirs(dir)
Esempio n. 56
0
    def __init__(self):

        # VAR SETUP#
        self.fileType = {0: "mayaAscii", 1: "mayaBinary"}
        self.filePath = os.path.abspath(cmds.file(q=True, sn=True))
        self.origFolder = os.path.dirname(self.filePath)
        self.origFilename = self.filePath.split("/")[-2:][1].split(".")[0]
        self.username = gp.getuser()
        self.newFile = 0
        self.folder_project = os.path.abspath(pm.workspace(q=True, rd=True))
        self.shot = "_".join(self.folder_project.split(os.path.sep)[-2:][:-1])
        self.folder_discipline = os.path.join("scenes", "model")
        self.optionalNote = ""
        self.versionOption_startup = 1

        self._parseFileName()

        # UI SETUP#
        title = "AW_Save_Plus"
        self.go_green_cl = [0.1, 0.4, 0.2]
        self.title_blue_cl = [0.1, 0.15, 0.2]
        self.go_yellow_cl = [0.947, 0.638, 0.130]
        if pm.windowPref(title, q=True, ex=True):
            pm.windowPref(title, remove=True)
        if pm.window(title, q=True, ex=True):
            pm.deleteUI(title)
        self.window = pm.window(title, t=title, w=890, h=105)

        self.fl = pm.formLayout()
        self.title_tx = pm.symbolButton(image="save_105.png", w=105, h=105)
        self.col = pm.columnLayout(p=self.fl)
        pm.text(l="Saving to Directory:", fn="boldLabelFont")
        self._updateFile(False)
        self.filePath_tx = pm.text("filePath_tx", l=self.file)
        pm.text(l="")
        self.header = pm.text("header_tf", fn="boldLabelFont", l="Filename")
        self.origFile_om = wind.AW_optionMenu(
            label="", options=["Original Folder", "Auto-detect"], parent=self.col, cc=self._changeOrigFolder_om
        )
        if self.newFile:
            self.origFile_om.setSelect(2)

        self.layout = pm.formLayout(nd=100)

        self.fileDescr_tf = pm.textField(
            "fileDescr_tf", text=self.fileDescr, p=self.layout, w=200, cc=self._changeFileDescr
        )
        self.discipline_om = wind.AW_optionMenu(
            label="_", options=self.disciplines, parent=self.layout, cc=self._changeDiscipline
        )
        self.spacer = pm.text(l="_v", p=self.layout, w=10)
        self.version_tf = pm.textField(
            "version_tf", text="%03d" % self.version, p=self.layout, w=30, cc=self._changeVersionNumber
        )
        self.versionOptional_om = wind.AW_optionMenu(
            label="",
            options=[
                "",
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
                "g",
                "h",
                "i",
                "j",
                "k",
                "l",
                "m",
                "n",
                "o",
                "p",
                "q",
                "r",
                "s",
                "t",
                "u",
                "v",
                "x",
                "y",
                "z",
            ],
            parent=self.layout,
            cc=self._changeVersionOptional_om,
        )
        self.optionalNote_tf = pm.textField(
            "optionalNote_tf", text="(optional note)", p=self.layout, w=150, cc=self._changeOptionalNoteTx
        )
        self.type = wind.AW_optionMenu(label="_", options=[".ma", ".mb"], parent=self.layout, cc=self._changeType_om)
        if self.initialFileType == "ma":
            self.type.setSelect(1)
        if self.initialFileType == "mb":
            self.type.setSelect(2)
        self.save_btn = pm.button(label="Save", command=self._save, h=20, bgc=self.go_yellow_cl)

        pm.formLayout(
            self.layout,
            e=True,
            af=[(self.fileDescr_tf, "left", 0), (self.spacer, "top", 5)],
            ac=[
                (self.discipline_om.optionMenu, "left", 5, self.fileDescr_tf),
                (self.spacer, "left", 5, self.discipline_om.optionMenu),
                (self.version_tf, "left", 5, self.spacer),
                (self.versionOptional_om.optionMenu, "left", 5, self.version_tf),
                (self.optionalNote_tf, "left", 5, self.versionOptional_om.optionMenu),
                (self.type.optionMenu, "left", 5, self.optionalNote_tf),
                (self.save_btn, "left", 5, self.type.optionMenu),
            ],
        )
        pm.formLayout(self.fl, e=True, af=[(self.col, "top", 10)], ac=[(self.col, "left", 10, self.title_tx)])

        self._setVersionOption(self.versionOption_startup)
        self._getDiscipline()
        self._updateFilename()
        self._updateFilePathTx()

        self.window.show()
Esempio n. 57
0
def importSkin(filePath=None, *args):

    if not filePath:
        f1 = 'mGear Skin (*{0} *{1})'.format(FILE_EXT, FILE_JSON_EXT)
        f2 = ";;gSkin Binary (*{0});;jSkin ASCII  (*{1})".format(
            FILE_EXT, FILE_JSON_EXT)
        f3 = ";;All Files (*.*)"
        fileFilters = f1 + f2 + f3
        startDir = pm.workspace(q=True, rootDirectory=True)
        filePath = pm.fileDialog2(dialogStyle=2,
                                  fileMode=1,
                                  startingDirectory=startDir,
                                  fileFilter=fileFilters)
    if not filePath:
        return
    if not isinstance(filePath, basestring):
        filePath = filePath[0]

    # Read in the file
    with open(filePath, 'r') as fp:
        if filePath.endswith(FILE_EXT):
            dataPack = pickle.load(fp)
        else:
            dataPack = json.load(fp)

    for data in dataPack["objDDic"]:
        # This checks if the jSkin file has the new style compressed format.
        # use a skinDataFormat key to check for backwards compatibility.
        # If it doesn't exist, just continue with the old method.
        compressed = False
        if data.has_key('skinDataFormat'):
            if data['skinDataFormat'] == 'compressed':
                compressed = True

        try:
            skinCluster = False
            objName = data["objName"]
            objNode = pm.PyNode(objName)

            try:
                # use getShapes() else meshes with 2+ shapes will fail.
                #TODO: multiple shape nodes is not currently supported in
                # the file structure! It should raise an error.
                # Also noIntermediate otherwise it will count shapeOrig nodes.
                objShapes = objNode.getShapes(noIntermediate=True)

                if isinstance(objNode.getShape(), pm.nodetypes.Mesh):
                    meshVertices = pm.polyEvaluate(objShapes, vertex=True)
                elif isinstance(objNode.getShape(), pm.nodetypes.NurbsSurface):
                    # if nurbs, count the cvs instead of the vertices.
                    meshVertices = sum([len(shape.cv) for shape in objShapes])
                elif isinstance(objNode.getShape(), pm.nodetypes.NurbsCurve):
                    meshVertices = sum([len(shape.cv) for shape in objShapes])
                else:
                    #TODO: Implement other skinnable objs like lattices.
                    meshVertices = 0

                if compressed:
                    importedVertices = data['vertexCount']
                else:
                    importedVertices = len(data['blendWeights'])
                if meshVertices != importedVertices:
                    warningMsg = 'Vertex counts do not match. {} != {}'
                    pm.displayWarning(
                        warningMsg.format(meshVertices, importedVertices))
                    continue
            except Exception:
                pass

            if getSkinCluster(objNode):
                skinCluster = getSkinCluster(objNode)
            else:
                try:
                    joints = data['weights'].keys()
                    skinCluster = pm.skinCluster(joints,
                                                 objNode,
                                                 tsb=True,
                                                 nw=2,
                                                 n=data['skinClsName'])
                except Exception:
                    sceneJoints = set(
                        [pm.PyNode(x).name() for x in pm.ls(type='joint')])
                    notFound = []
                    for j in data['weights'].keys():
                        if j not in sceneJoints:
                            notFound.append(str(j))
                    pm.displayWarning("Object: " + objName + " Skiped. Can't "
                                      "found corresponding deformer for the "
                                      "following joints: " + str(notFound))
                    continue
            if skinCluster:
                setData(skinCluster, data, compressed)
                print('Imported skin for: {}'.format(objName))

        except Exception:
            warningMsg = "Object: {} Skipped. Can NOT be found in the scene"
            pm.displayWarning(warningMsg.format(objName))
Esempio n. 58
0
    def launch(self, *args, **kwargs):
        """launch renderer command
        """
        # do nothing if there is no window (called externally)
        if not self.window:
            return

        # warn the user about the ignore settings
        try:
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            ignore_attrs = [
                'ignoreSubdivision',
                'ignoreDisplacement',
                'ignoreBump',
                'ignoreMotionBlur'
            ]

            attr_values = [
                (attr, dAO.getAttr(attr))
                for attr in ignore_attrs
                if dAO.getAttr(attr) is True
            ]

            if any(attr_values):
                msg_text = '<br>'.join(
                    map(
                        lambda x: '%s: %s' % (x[0], x[1]),
                        attr_values
                    )
                )

                response = pm.confirmDialog(
                    title='Ignore These Settings?',
                    message='You have ignored:<br><br>%s<br><br><b>Is that ok?</b>' % msg_text,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
        except pm.MayaNodeError:
            # no Arnold
            pass

        # check if rendering with persp camera
        try:
            wrong_camera_names = [
                'perspShape',
                'topShape',
                'sideShape',
                'fontShape',

                'persp1Shape',
                'perspShape1',
            ]
            renderable_cameras = [node for node in pm.ls(type='camera') if node.getAttr('renderable')]
            if any(map(lambda x: x.name() in wrong_camera_names, renderable_cameras)):
                response = pm.confirmDialog(
                    title='Rendering with Persp?',
                    message='You are rendering with <b>Persp Camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return

            if len(renderable_cameras) > 1:
                response = pm.confirmDialog(
                    title='Rendering more than one Camera?',
                    message='You are rendering <b>more than one camera<b><br><br>Is that ok?</b>',
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )

                if response == 'No':
                    return
            elif len(renderable_cameras) == 0:
                pm.confirmDialog(
                    title='No <b>Renderable</b> camera!!!',
                    message='There is no <b>renderable camera<b>!!!',
                    button=['Ok'],
                    defaultButton='Ok',
                    cancelButton='Ok',
                    dismissString='Ok'
                )
                return

        except pm.MayaNodeError:
            # no default render globals node
            pass

        drg = pm.PyNode('defaultRenderGlobals')
        render_engine = drg.getAttr('currentRenderer')
        # RENDERER SPECIFIC CHECKS

        if render_engine == 'redshift':
            # if the renderer is RedShift
            # check if unifiedDisableDivision is 1 which will take too much time
            # to render
            dro = pm.PyNode('redshiftOptions')
            if dro.unifiedDisableDivision.get() == 1:
                response = pm.confirmDialog(
                    title="Enabled **Don't Automatically Reduce Samples of Other Effects**",
                    message='It is not allowed to render with the following option is enabled:<br>'
                            '<br>'
                            "Don't Automatically Reduce Samples of Other Effects: Enabled<br>"
                            "<br>"
                            "Please DISABLE it!",
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check dome light backgrounds
            domes_to_fix = []
            rs_domes = pm.ls(type='RedshiftDomeLight')
            if rs_domes:
                for rs_dome in rs_domes:
                    if rs_dome.getAttr('background_enable') == 1 \
                       or rs_dome.getAttr('backPlateEnabled') == 1:
                        domes_to_fix.append(rs_dome.name())

            if domes_to_fix:
                message = 'Some DomeLights have <b>BackGround Render ' \
                          'Enabled</b>:' \
                          '<br><br>%s<br><br>' \
                          'Are you Sure?' % '<br>'.join(domes_to_fix)

                response = pm.confirmDialog(
                    title='Dome Lights with Background Enabled?',
                    message=message,
                    button=['Yes', 'No'],
                    defaultButton='No',
                    cancelButton='No',
                    dismissString='No'
                )
                if response == 'No':
                    return

            # abort on license fail
            dro.abortOnLicenseFail.set(1)

        elif render_engine == 'arnold':
            # check if the samples are too high
            dAO = pm.PyNode('defaultArnoldRenderOptions')

            aa_samples = dAO.AASamples.get()
            diff_samples = dAO.GIDiffuseSamples.get()
            try:
                glossy_samples = dAO.GIGlossySamples.get()
            except AttributeError:
                glossy_samples = dAO.GISpecularSamples.get()
            if int(pm.about(v=1)) >= 2017:
                sss_samples = dAO.GISssSamples.get()
            else:
                sss_samples = dAO.sssBssrdfSamples.get()

            total_diff_samples = aa_samples**2 * diff_samples**2
            total_glossy_samples = aa_samples**2 * glossy_samples**2
            total_sss_samples = aa_samples**2 * sss_samples**2

            max_allowed_diff_samples = 225
            max_allowed_glossy_samples = 100
            max_allowed_sss_samples = 800

            if total_diff_samples > max_allowed_diff_samples:
                pm.confirmDialog(
                    title="Too Much Diffuse Samples!!!",
                    message='You are using too much DIFFUSE SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Diffuse '
                            'Samples!!!' % max_allowed_diff_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_glossy_samples > max_allowed_glossy_samples:
                pm.confirmDialog(
                    title="Too Much Glossy Samples!!!",
                    message='You are using too much GLOSSY SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of Glossy '
                            'Samples!!!' % max_allowed_glossy_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            if total_sss_samples > max_allowed_sss_samples:
                pm.confirmDialog(
                    title="Too Much SSS Samples!!!",
                    message='You are using too much SSS SAMPLES (>%s)<br>'
                            '<br>'
                            'Please either reduce AA samples of SSS '
                            'Samples!!!' % max_allowed_sss_samples,
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # check Light Samples
            # check point lights with zero radius but more than one samples
            all_point_lights = pm.ls(type='pointLight')
            ridiculous_point_lights = []
            for point_light in all_point_lights:
                if point_light.aiRadius.get() < 0.1 and point_light.aiSamples.get() > 1:
                    ridiculous_point_lights.append(point_light)

            if ridiculous_point_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Point Lights!!!",
                    message='You are using too much SAMPLES (>1)<br>'
                            '<br>'
                            'on <b>Point lights with zero radius</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check area lights with more than 2 samples
            all_area_lights = pm.ls(type=['areaLight', 'aiAreaLight'])
            ridiculous_area_lights = []
            for area_light in all_area_lights:
                if area_light.aiSamples.get() > 2:
                    ridiculous_area_lights.append(area_light)

            if ridiculous_area_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Area Lights!!!",
                    message='You are using too much SAMPLES (>2) on<br>'
                            '<br>'
                            '<b>Area Lights</b><br>'
                            '<br>'
                            'Please reduce the samples to 2',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

            # Check directional lights with angle == 0 and samples > 1
            all_directional_lights = pm.ls(type='directionalLight')
            ridiculous_directional_lights = []
            dir_sample_attr_name = 'aiSamples'
            # if pm.about(v=1) == "2014":
            #     dir_sample_attr_name = 'aiSamples'

            for directional_light in all_directional_lights:
                if directional_light.aiAngle.get() == 0 and directional_light.attr(dir_sample_attr_name).get() > 1:
                    ridiculous_directional_lights.append(directional_light)

            if ridiculous_directional_lights:
                pm.confirmDialog(
                    title="Unnecessary Samples on Directional Lights!!!",
                    message='You are using too much SAMPLES (>1) on <br>'
                            '<br>'
                            '<b>Directional lights with zero angle</b><br>'
                            '<br>'
                            'Please reduce the samples to 1',
                    button=['OK'],
                    defaultButton='OK',
                    cancelButton='OK',
                    dismissString='OK'
                )
                return

        # get values
        start_frame = pm.intField('cgru_afanasy__start_frame', q=1, v=1)
        end_frame = pm.intField('cgru_afanasy__end_frame', q=1, v=1)
        frames_per_task = \
            pm.intField('cgru_afanasy__frames_per_task', q=1, v=1)
        by_frame = pm.intField('cgru_afanasy__by_frame', q=1, v=1)
        hosts_mask = pm.textField('cgru_afanasy__hosts_mask', q=1, text=True)
        hosts_exclude = pm.textField('cgru_afanasy__hosts_exclude', q=1, text=True)
        separate_layers = \
            pm.radioButtonGrp('cgru_afanasy__separate_layers', q=1, sl=1)
        pause = pm.checkBox('cgru_afanasy__paused', q=1, v=1)
        life_time = pm.intField('cgru_afanasy__life_time', q=1, v=1)
        annotation = pm.textField('cgru_afanasy__annotation', q=1, text=True)
        submit_multiple_times = pm.intField('cgru_afanasy__submit_multiple_times', q=1, v=1)
        errors_avoid_host = pm.intField('cgru_afanasy__errors_avoid_host', q=1, v=1)
        errors_retries = pm.intField('cgru_afanasy__errors_retries', q=1, v=1)
        errors_task_same_host = pm.intField('cgru_afanasy__errors_task_same_host', q=1, v=1)
        errors_forgive_time = pm.intField('cgru_afanasy__errors_forgive_time', q=1, v=1)

        # check values
        if start_frame > end_frame:
            temp = end_frame
            end_frame = start_frame
            start_frame = temp

        frames_per_task = max(1, frames_per_task)
        by_frame = max(1, by_frame)

        # store without quota sign
        hosts_mask = hosts_mask.replace('"', '')
        hosts_exclude = hosts_exclude.replace('"', '')

        # store field values
        pm.optionVar['cgru_afanasy__start_frame_ov'] = start_frame
        pm.optionVar['cgru_afanasy__end_frame_ov'] = end_frame
        pm.optionVar['cgru_afanasy__frames_per_task_ov'] = frames_per_task
        pm.optionVar['cgru_afanasy__by_frame_ov'] = by_frame
        pm.optionVar['cgru_afanasy__hosts_mask_ov'] = hosts_mask
        pm.optionVar['cgru_afanasy__hosts_exclude_ov'] = hosts_exclude
        pm.optionVar['cgru_afanasy__separate_layers_ov'] = separate_layers
        pm.optionVar['cgru_afanasy__life_time_ov'] = life_time
        pm.optionVar['cgru_afanasy__annotation_ov'] = annotation

        pm.optionVar['cgru_afanasy__submit_multiple_times_ov'] = submit_multiple_times
        pm.optionVar['cgru_afanasy__errors_avoid_host_ov'] = errors_avoid_host
        pm.optionVar['cgru_afanasy__errors_retries_ov'] = errors_retries
        pm.optionVar['cgru_afanasy__errors_task_same_host_ov'] = errors_task_same_host
        pm.optionVar['cgru_afanasy__errors_errors_forgive_time_ov'] = errors_forgive_time

        # get paths
        scene_name = pm.sceneName()
        datetime = '%s%s' % (
            time.strftime('%y%m%d-%H%M%S-'),
            str(time.time() - int(time.time()))[2:5]
        )

        filename = '%s.%s.mb' % (scene_name, datetime)

        project_path = pm.workspace(q=1, rootDirectory=1)

        # outputs = \
        #     pm.renderSettings(fullPath=1, firstImageName=1, lastImageName=1)

        # get output paths, set the RenderPass token to Beauty,
        # this will at least guarantee to get something
        outputs = \
            pm.renderSettings(
                fullPath=1, firstImageName=1, lastImageName=1,
                leaveUnmatchedTokens=1, customTokenString="RenderPass=Beauty"
            )

        # job_name = os.path.basename(scene_name)
        job_name = self.generate_job_name()

        logger.debug('%ss %se %sr' % (start_frame, end_frame, by_frame))
        logger.debug('scene                 = %s' % scene_name)
        logger.debug('file                  = %s' % filename)
        logger.debug('job_name              = %s' % job_name)
        logger.debug('project_path          = %s' % project_path)
        logger.debug('outputs               = %s' % outputs)
        logger.debug('annotation            = %s' % annotation)
        logger.debug('separate_layers       = %s' % separate_layers)
        logger.debug('errors_avoid_host     = %s' % errors_avoid_host)
        logger.debug('errors_retries        = %s' % errors_retries)
        logger.debug('errors_task_same_host = %s' % errors_task_same_host)
        logger.debug('errors_forgive_time   = %s' % errors_forgive_time)

        if pm.checkBox('cgru_afanasy__close', q=1, v=1):
            pm.deleteUI(self.window)

        stored_log_level = None
        if render_engine == 'arnold':
            # set the verbosity level to warning+info
            aro = pm.PyNode('defaultArnoldRenderOptions')
            stored_log_level = aro.getAttr('log_verbosity')
            aro.setAttr('log_verbosity', 2)
            # set output to console
            aro.setAttr("log_to_console", 1)
        elif render_engine == 'redshift':
            # set the verbosity level to detailed+info
            redshift = pm.PyNode('redshiftOptions')
            stored_log_level = redshift.logLevel.get()
            redshift.logLevel.set(2)

        # save file
        pm.saveAs(
            filename,
            force=1,
            type='mayaBinary'
        )

        # rename back to original name
        pm.renameFile(scene_name)

        # create the render command
        mrc = MayaRenderCommandBuilder(
            name=job_name,
            file_full_path=filename,
            render_engine=render_engine,
            project=project_path,
            by_frame=by_frame
        )

        # submit renders
        jobs = []
        blocks = []

        #
        # separate_layers:
        # 1 -> None  -> submit one job with a single block with all layers
        # 2 -> Block -> submit one job with multiple blocks
        # 3 -> Job   -> submit multiple jobs with a single block per layer
        #
        if separate_layers in [1, 2]:
            job = af.Job(job_name)
            jobs.append(job)

        if separate_layers in [2, 3]:
            # render each layer separately
            rlm = pm.PyNode('renderLayerManager')
            layers = [layer for layer in rlm.connections()
                      if layer.renderable.get()]

            for layer in layers:
                mrc_layer = copy.copy(mrc)
                layer_name = layer.name()
                mrc_layer.name = layer_name
                mrc_layer.render_layer = layer_name

                # create a new block for this layer
                block = af.Block(
                    layer_name,
                    renderer_to_block_type.get(render_engine, 'maya')
                )

                # Fix the output path for this layer
                # by replacing the "masterLayer" with the layer name
                # without rs_ at the beginning
                layer_outputs = outputs
                if layer_name != 'defaultRenderLayer':
                    layer_outputs[0] = outputs[0].replace(
                        'masterLayer',
                        layer_name.replace('rs_', '')
                    )
                    layer_outputs[1] = outputs[1].replace(
                        'masterLayer',
                        layer_name.replace('rs_', '')
                    )

                outputs_split = afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(
                            layer_outputs[0],
                            layer_outputs[1]
                        )
                    )
                ).split(';')

                block.setFiles(outputs_split)

                block.setNumeric(
                    start_frame, end_frame, frames_per_task, by_frame
                )
                command = mrc_layer.build_command()

                block.setErrorsAvoidHost(errors_avoid_host)
                block.setErrorsRetries(errors_retries)
                block.setErrorsTaskSameHost(errors_task_same_host)
                block.setErrorsForgiveTime(errors_forgive_time)

                block.setCommand(command)

                if separate_layers == 2:
                    blocks.append(block)
                else:
                    job = af.Job('%s - %s' % (job_name, layer_name))
                    # add blocks
                    job.blocks = [block]
                    jobs.append(job)

        else:
            # create only one block
            block = af.Block(
                'All Layers',
                renderer_to_block_type.get(render_engine, 'maya')
            )

            block.setFiles(
                afcommon.patternFromDigits(
                    afcommon.patternFromStdC(
                        afcommon.patternFromPaths(outputs[0], outputs[1])
                    )
                ).split(';')
            )
            block.setNumeric(
                start_frame, end_frame, frames_per_task, by_frame
            )
            command = mrc.build_command()
            block.setCommand(command)

            blocks.append(block)

        for job in jobs:
            job.setAnnotation(annotation)
            job.setFolder('input', os.path.dirname(filename))
            job.setFolder('output', os.path.dirname(outputs[0]))
            job.setHostsMask(hosts_mask)
            job.setHostsMaskExclude(hosts_exclude)
            if life_time > 0:
                job.setTimeLife(life_time * 3600)
            else:
                job.setTimeLife(240 * 3600)

            job.setCmdPost('deletefiles -s "%s"' % os.path.abspath(filename))
            if pause:
                job.offline()

            # add blocks
            if separate_layers in [1, 2]:
                job.blocks.extend(blocks)

            for i in range(submit_multiple_times):
                orig_job_name = job.data['name']
                job.setName('%s - %03i' % (orig_job_name, i + 1))
                status, data = job.send()

                # restore job name
                job.setName(orig_job_name)
                if not status:
                    pm.PopupError('Something went wrong!')

        # restore log level
        if render_engine == 'arnold':
            aro = pm.PyNode('defaultArnoldRenderOptions')
            aro.setAttr('log_verbosity', stored_log_level)
            # disable set output to console
            aro.setAttr("log_to_console", 0)
        elif render_engine == 'redshift':
            redshift = pm.PyNode('redshiftOptions')
            redshift.logLevel.set(stored_log_level)

            # disable abort on license fail
            redshift.abortOnLicenseFail.set(0)