def exportYeti(path): yeitInfo = getYetiInfo() if pm.objExists('yetiInfoNode'): yetiInfoNode = pm.PyNode('yetiInfoNode') yetiInfoNode.unlock() pm.delete(yetiInfoNode) attrName = 'yetiInfo' yetiInfoNode = pm.createNode('network', n='yetiInfoNode') yetiInfoNode.addAttr(attrName, dt='string') jsonHandl = json.dumps(yeitInfo) yetiInfoNode.attr(attrName).set(jsonHandl) yetiInfoNode.attr(attrName).lock() yetiInfoNode.lock() exportList = [yetiInfoNode] for _, shader in yeitInfo.items(): exportList.append(shader) pm.select(exportList) try: pm.exportSelected(path, pr=1, typ='mayaBinary', force=1, es=1) print 'Success Export Shader' except: print exportList print path finally: yetiInfoNode.unlock() pm.delete(yetiInfoNode)
#fname = cmds.file( location=True, query=True ) #fnameParts = fname.split('.') ## any string then .join will combine a list by the string before .join #fname = ".".join( fnameParts[0:-1] ) #ename = "__FORUDK.fbx" #fname = fname + ename pm.exportSelected( fname,
def exportAsObj(self): pm.exportSelected( 'd:/deletemeLiamExport.obj', shader=1, force=True, typ="OBJexport", #pr = 1, ## #es = 1, )
def exportShader(path): """씬안에 쉐이딩 그룹으로 부터 정보를 모아 shaderInfoNode에 저장 한후 입력 받은 경로에 shader를 저장 한다. :param path: 파일 경로 :type path: str """ sgGrps = getShadingEngine() shaderInfos = [] exportList = [] for sg in sgGrps: shaderInfo = getShaderInfo(sg) shaderInfos.append(shaderInfo) if shaderInfo['surfaceShader'] != '': exportList.append(shaderInfo['surfaceShader']) if shaderInfo['displacement'] != '': exportList.append(shaderInfo['displacement']) numAttr = len(shaderInfos) if pm.objExists('shaderInfoNode'): shaderInfoNode = pm.PyNode('shaderInfoNode') shaderInfoNode.unlock() pm.delete(shaderInfoNode) shaderInfoNode = pm.createNode('network', n='shaderInfoNode') shaderInfoNode.addAttr('shaderInfos', at='compound', nc=numAttr) for i in range(numAttr): attrName = 'shaderInfos' + str(i) shaderInfoNode.addAttr(attrName, dt='string', p='shaderInfos') for i, shaderInfo in enumerate(shaderInfos): attrName = 'shaderInfos' + str(i) jsonHandl = json.dumps(shaderInfo) shaderInfoNode.attr(attrName).set(jsonHandl) shaderInfoNode.attr(attrName).lock() shaderInfoNode.lock() exportList.append(shaderInfoNode) pm.select(exportList) try: pm.exportSelected(path, pr=1, typ='mayaBinary', force=1, es=1) print 'Success Export Shader' except: print exportList print path finally: shaderInfoNode.unlock() pm.delete(shaderInfoNode)
def exportAsFbxForUdk(self): originalSelection = pm.ls(selection=True) cmd = 'FBXLoadExportPresetFile -f "' + PresetFileNameWithPathForUdk + '";' #print(cmd) pm.mel.eval(cmd) pm.exportSelected( fname, shader=1, force=True, typ="FBX export", #pr = 1, ## #es = 1, ) pm.select(originalSelection)
pass def exportAsObj(self): pm.exportSelected( 'd:/deletemeLiamExport.obj', shader = 1, force=True, typ = "OBJexport", #pr = 1, ## #es = 1, ) def buildOutputFileNameWithPath( self, newEnding ): fname = cmds.file( location=True, query=True ) fnameParts = fname.split('.') ## any string then .join will combine a list by the string before .join fname = ".".join( fnameParts[0:-1] ) ename = "__FORUDK.fbx"
def go(self): user_path = str( raw_input() ) sel = pm.ls(selection=True) sel_orig = Copy(sel) for obj in sel: #print( type(obj) ) ## Bail early if it's not a transform node if not isinstance(obj, pm.core.nodetypes.Transform): continue pm.select(obj, replace=True, hierarchy=True) suf = self.mesh_suffix dir = user_path.replace('\\', '/' ) dest = dir + '/' + obj.name() + suf + '.fbx' fmt = 'FBX export' pm.exportSelected( dest, type=fmt, es=True ) pm.select( clear=True )
def bake( self, modelsPath="", highSuffix="", xnormalExe="", xmlFiles="", cageSuffix="", typeSuffixes="", cageOffset=None ): try: cmds.progressWindow( endProgress=True ) except: pass #print( "..." ) cmds.progressWindow(isInterruptable=1) if highSuffix=="": highSuffix="_hi" if cageSuffix=="": cageSuffix= "_cage" if cageOffset==None: cageOffset=2.0 if typeSuffixes=="": typeSuffixes=['normals','heights','vcols', 'occlusion', 'curvature', 'cavity'] typeOfTypeSuffixes = type(typeSuffixes) if typeOfTypeSuffixes==type( "a_string" ) or typeOfTypeSuffixes==type( u"a_unicode_string" ): typeSuffixes = typeSuffixes.split(",") xnormal_exe = xnormalExe.replace("\\","/") folder_with_high_models = modelsPath.replace("\\","/") xml_files = xmlFiles.split(',') objExt = ".obj" ## Set pythons current working directory os.chdir( folder_with_high_models ) ## Get the selected objects, store as both an original selection ## and a copy of the original selection, objs osel = pm.ls(selection=True) objs = osel[:] scriptIsCanceled = False cancelCheckSleepTimeStartup = 0.5 cancelCheckSleepTime = 0.01 for obj in objs: time.sleep( cancelCheckSleepTimeStartup ) if cmds.progressWindow(query=1, isCancelled=1): print( "Script canceled by user, eg. escape key." ) scriptIsCanceled = True break try: ## try each obj ## Select the object and set up some basic variables, ## such as the name and the python cwd pm.select( obj ) obj_name = obj.name() cwd = os.getcwd() cwdUni = unicode(cwd) ## Triangulate before export print( obj ) tri_op = pm.polyTriangulate( obj ) ## Export lo, triangulated export_target_including_file_and_path = os.getcwd().replace("\\","/") + "/" + obj_name + objExt pm.select( obj ) pm.exportSelected( export_target_including_file_and_path,sh = 1, pr = 1, typ = "OBJexport", es = 1, force=True ) print( obj ) try: cageOffsetCustom = obj.mmmmBakerCageOffset.get() except: cageOffsetCustom = cageOffset print( "no custom cage offset found, using default" ) trans_op = pm.polyMoveVertex( obj, localTranslateZ=cageOffsetCustom ) ## Export Cage export_target_including_file_and_path = \ os.getcwd().replace("\\","/") + "/" + obj_name + cageSuffix + objExt pm.select( obj ) pm.exportSelected( export_target_including_file_and_path, sh = 1, pr = 1, typ = "OBJexport", es = 1, force=True ) ## Cleanup cage offset and triangulation pm.delete( trans_op ) pm.delete( tri_op ) #if obj_name.endswith( lo_suffix ): # high_name = obj_name.replace( lo_suffix, highSuffix ) #else: high_name = obj_name + highSuffix for i, xml_file in enumerate(xml_files): time.sleep( cancelCheckSleepTime ) if cmds.progressWindow(query=1, isCancelled=1): scriptIsCanceled=True print( "Script canceled by user, eg. escape key." ) break pm.select( obj ) pm.mel.eval( "ConvertSelectionToUVs;" ) uvs = pm.ls(selection=True, flatten=True) coUV = pm.polyEditUV( uvs, query=True ) coU, coV = coUV[::2], coUV[1::2] pm.select(obj) """" for c in coU: if c >= 0.0 and c < 1.0: udim1001=True if c >= 1.0 and c < 2.0: udim1002=True if c >= 2.0 and c < 3.0: udim1003=True if c >= 3.0 and c < 4.0: udim1004=True """ dictOfUsedUvRanges = {} for cIndex in xrange( len(coU) ): tu = coU[cIndex] tv = coV[cIndex] tuInt = math.floor( tu ) tvInt = math.floor( tv ) dictOfUsedUvRanges[ tuInt,tvInt ] = int( 1000 + (tuInt+1) + (tvInt*10) ) #print( "length of dictionary:") #print( len( dictOfUsedUvRanges.keys() ) ) #break for keyRange, udim in dictOfUsedUvRanges.items(): uInKey = keyRange[0] vInKey = keyRange[1] uOffset = uInKey * -1.0 vOffset = vInKey * -1.0 if uOffset==0.0: uOffset=0.0 #in case of negative 0.0, f*****g hell! if vOffset==0.0: vOffset=0.0 #in case of negative 0.0, f*****g hell! # do something similar for vOffset. ## edit xml export with uOffset and uOffset here! """" if udim1001==True: uOffsets.append( 0.0 ) if udim1002==True: uOffsets.append( -1.0 ) if udim1003==True: uOffsets.append( -2.0 ) if udim1004==True: uOffsets.append( -3.0 ) for uOffset in uOffsets: """ time.sleep( cancelCheckSleepTime ) if cmds.progressWindow(query=1, isCancelled=1): scriptIsCanceled=True print( "Script canceled by user, eg. escape key." ) break xml_file_abs = os.path.join( cwdUni, xml_file ) print( xml_file_abs ) xml_file_modified = u'tmp_mmmmBaker.xml' xml_file_modified_abs = os.path.join( cwdUni, xml_file_modified ) xml_in_mem = '' with open( xml_file_abs, 'r' ) as fh: xml_in_mem = fh.read() xml_in_mem = xml_in_mem.replace( 'UOffset="0.', 'UOffset="' + str(uOffset) ) xml_in_mem = xml_in_mem.replace( 'VOffset="0.', 'VOffset="' + str(vOffset) ) uOffsetAsInt = int( -1 * uOffset) vOffsetAsInt = int( -1 * uOffset) folder_with_high_models__no_trailing_slash = \ folder_with_high_models if folder_with_high_models__no_trailing_slash.endswith("/"): folder_with_high_models__no_trailing_slash =\ folder_with_high_models__no_trailing_slash[:-1] xml_in_mem = xml_in_mem.replace( "C:\\Users\\Public\\mmmmBaker", folder_with_high_models.replace("/","\\") ) root = XmlTree.fromstring(xml_in_mem) ## Print the entire xml tree for reference' #print( XmlTree.tostring( root ) ) ## find used udims on objects ## find u offset and v offset for low objects ## set up a list to run a for loop for to ## handle each udim found ## find low object ## find cage object ## find use cage option # ## find hi objects ## find output with open( xml_file_modified_abs, 'w' ) as fh: fh.write( xml_in_mem ) print( obj ) ##print( xml_in_mem ) print( uOffsetAsInt, vOffsetAsInt ) try: lo_to_copy_for_replacement = obj_name + objExt cage_to_copy_for_replacement = obj_name + cageSuffix + objExt hi_to_copy_for_replacement = obj_name + highSuffix + objExt shutil.copy2(lo_to_copy_for_replacement, "replaceme_lo" + objExt) shutil.copy2(hi_to_copy_for_replacement, "replaceme_hi" + objExt) shutil.copy2(cage_to_copy_for_replacement, "replaceme_cage" + objExt) print( "xnormal subprocess starting...") print( xnormal_exe + " " + str(xml_file_modified) ) subprocess.check_call( [ xnormal_exe, str(xml_file_modified) ] ) print( "xnormal subprocess complete! Continuing...") for typeSuffix in typeSuffixes: try: baked_name = "replaceme_" + typeSuffix + ".exr" proper_name = obj_name + "_" + "xml"+str(i).zfill(2) + "_" + "udim" + str( udim ) + "_" + typeSuffix + ".exr" shutil.copy2( baked_name, proper_name ) except: print( traceback.format_exc() ) except: print( traceback.format_exc() ) except: ## except each obj print( traceback.format_exc() ) pm.select( osel ) ## Do something here to attempt to combine/composite textures together. ## Until then, just tell the user to use the photoshop action ## which should be provided with MmmmTools ## Add some explaination for how to use the action cmds.progressWindow( endProgress=True ) if not scriptIsCanceled: print( "Baking complete!") print( "Baked (or at least attempted to bake) " + str( len(objs) ) + " objects." )
def bake(self, modelsPath="", highSuffix="", xnormalExe="", xmlFiles="", cageSuffix="", typeSuffixes="", cageOffset=None): try: cmds.progressWindow(endProgress=True) except: pass #print( "..." ) cmds.progressWindow(isInterruptable=1) if highSuffix == "": highSuffix = "_hi" if cageSuffix == "": cageSuffix = "_cage" if cageOffset == None: cageOffset = 2.0 if typeSuffixes == "": typeSuffixes = [ 'normals', 'heights', 'vcols', 'occlusion', 'curvature', 'cavity' ] typeOfTypeSuffixes = type(typeSuffixes) if typeOfTypeSuffixes == type( "a_string") or typeOfTypeSuffixes == type(u"a_unicode_string"): typeSuffixes = typeSuffixes.split(",") xnormal_exe = xnormalExe.replace("\\", "/") folder_with_high_models = modelsPath.replace("\\", "/") xml_files = xmlFiles.split(',') objExt = ".obj" ## Set pythons current working directory os.chdir(folder_with_high_models) ## Get the selected objects, store as both an original selection ## and a copy of the original selection, objs osel = pm.ls(selection=True) objs = osel[:] scriptIsCanceled = False cancelCheckSleepTimeStartup = 0.5 cancelCheckSleepTime = 0.01 for obj in objs: time.sleep(cancelCheckSleepTimeStartup) if cmds.progressWindow(query=1, isCancelled=1): print("Script canceled by user, eg. escape key.") scriptIsCanceled = True break try: ## try each obj ## Select the object and set up some basic variables, ## such as the name and the python cwd pm.select(obj) obj_name = obj.name() cwd = os.getcwd() cwdUni = unicode(cwd) ## Triangulate before export print(obj) tri_op = pm.polyTriangulate(obj) ## Export lo, triangulated export_target_including_file_and_path = os.getcwd().replace( "\\", "/") + "/" + obj_name + objExt pm.select(obj) pm.exportSelected(export_target_including_file_and_path, sh=1, pr=1, typ="OBJexport", es=1, force=True) print(obj) try: cageOffsetCustom = obj.mmmmBakerCageOffset.get() except: cageOffsetCustom = cageOffset print("no custom cage offset found, using default") trans_op = pm.polyMoveVertex(obj, localTranslateZ=cageOffsetCustom) ## Export Cage export_target_including_file_and_path = \ os.getcwd().replace("\\","/") + "/" + obj_name + cageSuffix + objExt pm.select(obj) pm.exportSelected(export_target_including_file_and_path, sh=1, pr=1, typ="OBJexport", es=1, force=True) ## Cleanup cage offset and triangulation pm.delete(trans_op) pm.delete(tri_op) #if obj_name.endswith( lo_suffix ): # high_name = obj_name.replace( lo_suffix, highSuffix ) #else: high_name = obj_name + highSuffix for i, xml_file in enumerate(xml_files): time.sleep(cancelCheckSleepTime) if cmds.progressWindow(query=1, isCancelled=1): scriptIsCanceled = True print("Script canceled by user, eg. escape key.") break pm.select(obj) pm.mel.eval("ConvertSelectionToUVs;") uvs = pm.ls(selection=True, flatten=True) coUV = pm.polyEditUV(uvs, query=True) coU, coV = coUV[::2], coUV[1::2] pm.select(obj) """" for c in coU: if c >= 0.0 and c < 1.0: udim1001=True if c >= 1.0 and c < 2.0: udim1002=True if c >= 2.0 and c < 3.0: udim1003=True if c >= 3.0 and c < 4.0: udim1004=True """ dictOfUsedUvRanges = {} for cIndex in xrange(len(coU)): tu = coU[cIndex] tv = coV[cIndex] tuInt = math.floor(tu) tvInt = math.floor(tv) dictOfUsedUvRanges[tuInt, tvInt] = int(1000 + (tuInt + 1) + (tvInt * 10)) #print( "length of dictionary:") #print( len( dictOfUsedUvRanges.keys() ) ) #break for keyRange, udim in dictOfUsedUvRanges.items(): uInKey = keyRange[0] vInKey = keyRange[1] uOffset = uInKey * -1.0 vOffset = vInKey * -1.0 if uOffset == 0.0: uOffset = 0.0 #in case of negative 0.0, f*****g hell! if vOffset == 0.0: vOffset = 0.0 #in case of negative 0.0, f*****g hell! # do something similar for vOffset. ## edit xml export with uOffset and uOffset here! """" if udim1001==True: uOffsets.append( 0.0 ) if udim1002==True: uOffsets.append( -1.0 ) if udim1003==True: uOffsets.append( -2.0 ) if udim1004==True: uOffsets.append( -3.0 ) for uOffset in uOffsets: """ time.sleep(cancelCheckSleepTime) if cmds.progressWindow(query=1, isCancelled=1): scriptIsCanceled = True print("Script canceled by user, eg. escape key.") break xml_file_abs = os.path.join(cwdUni, xml_file) print(xml_file_abs) xml_file_modified = u'tmp_mmmmBaker.xml' xml_file_modified_abs = os.path.join( cwdUni, xml_file_modified) xml_in_mem = '' with open(xml_file_abs, 'r') as fh: xml_in_mem = fh.read() xml_in_mem = xml_in_mem.replace( 'UOffset="0.', 'UOffset="' + str(uOffset)) xml_in_mem = xml_in_mem.replace( 'VOffset="0.', 'VOffset="' + str(vOffset)) uOffsetAsInt = int(-1 * uOffset) vOffsetAsInt = int(-1 * uOffset) folder_with_high_models__no_trailing_slash = \ folder_with_high_models if folder_with_high_models__no_trailing_slash.endswith( "/"): folder_with_high_models__no_trailing_slash =\ folder_with_high_models__no_trailing_slash[:-1] xml_in_mem = xml_in_mem.replace( "C:\\Users\\Public\\mmmmBaker", folder_with_high_models.replace("/", "\\")) root = XmlTree.fromstring(xml_in_mem) ## Print the entire xml tree for reference' #print( XmlTree.tostring( root ) ) ## find used udims on objects ## find u offset and v offset for low objects ## set up a list to run a for loop for to ## handle each udim found ## find low object ## find cage object ## find use cage option # ## find hi objects ## find output with open(xml_file_modified_abs, 'w') as fh: fh.write(xml_in_mem) print(obj) ##print( xml_in_mem ) print(uOffsetAsInt, vOffsetAsInt) try: lo_to_copy_for_replacement = obj_name + objExt cage_to_copy_for_replacement = obj_name + cageSuffix + objExt hi_to_copy_for_replacement = obj_name + highSuffix + objExt shutil.copy2(lo_to_copy_for_replacement, "replaceme_lo" + objExt) shutil.copy2(hi_to_copy_for_replacement, "replaceme_hi" + objExt) shutil.copy2(cage_to_copy_for_replacement, "replaceme_cage" + objExt) print("xnormal subprocess starting...") print(xnormal_exe + " " + str(xml_file_modified)) subprocess.check_call( [xnormal_exe, str(xml_file_modified)]) print( "xnormal subprocess complete! Continuing...") for typeSuffix in typeSuffixes: try: baked_name = "replaceme_" + typeSuffix + ".exr" proper_name = obj_name + "_" + "xml" + str( i).zfill(2) + "_" + "udim" + str( udim) + "_" + typeSuffix + ".exr" shutil.copy2(baked_name, proper_name) except: print(traceback.format_exc()) except: print(traceback.format_exc()) except: ## except each obj print(traceback.format_exc()) pm.select(osel) ## Do something here to attempt to combine/composite textures together. ## Until then, just tell the user to use the photoshop action ## which should be provided with MmmmTools ## Add some explaination for how to use the action cmds.progressWindow(endProgress=True) if not scriptIsCanceled: print("Baking complete!") print("Baked (or at least attempted to bake) " + str(len(objs)) + " objects.")
def exportPass(self, layers = list(), path = None): if not layers: OpenMaya.MGlobal.displayError('[Arsenal] Please select pass') return if not path: return splited = os.path.basename(path[0]).split('__') director = os.path.dirname(path[0]) if '.arpass' in splited[-1] and len(splited) != 1: splited.pop(-1) cleaned = '_'.join(splited) for layer in layers: renderLayer = pm.PyNode(layer) suffix = '__' + renderLayer.name() finalPath = os.path.join(director, cleaned.split('.')[0] + suffix + '.arpass') toExport = layer + '_arsenalPass' pm.select(toExport, r=True) pm.exportSelected(finalPath, force=True, options='v=0;', type='mayaAscii', pr=True, constructionHistory=False, channels=False, constraints=False, expressions=False, shader=False) shutil.move(finalPath + '.ma', finalPath) pm.select(cl=True) objConnected = pm.listConnections(toExport, plugs=True, c=True) if not objConnected: continue info = {} dicConnect = {} infoLayer = {} infoLayer['name'] = layer infoLayer['global'] = renderLayer.g.get() listMembersLayer = {} for strMember in renderLayer.listMembers(fullNames=True): member = pm.PyNode(strMember) shortName = member.name() longName = member.longName() longNameWithoutNameSpace = pm.NameParser(longName).stripNamespace() shortNameWithoutNamespace = member.stripNamespace() listMembersLayer[str(longName)] = [str(longName), str(shortName), str(longNameWithoutNameSpace), str(shortNameWithoutNamespace)] infoLayer['members'] = listMembersLayer dicConnect['layer'] = infoLayer for connect in objConnected: dst = connect[0].name() src = connect[1] srcNodeName = src.nodeName() srcAttrName = src.attrName(longName=True) srcShort = src.name() srcAttr = src.longName(fullPath=True) srcShortWithoutNamespace = src.node().stripNamespace() + '.' + srcAttr srcLong = src.node().longName() + '.' + srcAttr srcLongWithoutNamespace = pm.NameParser(srcLong).stripNamespace() if str(srcLong) in info: actualDst = info[str(srcLong)]['destination'] actualDst.append(dst) info[str(srcLong)] = {'destination': actualDst, 'sources': [str(srcLong), str(srcShort), str(srcLongWithoutNamespace), str(srcShortWithoutNamespace)]} else: info[str(srcLong)] = {'destination': [dst], 'sources': [str(srcLong), str(srcShort), str(srcLongWithoutNamespace), str(srcShortWithoutNamespace)]} dicConnect['connections'] = info path = os.path.join(director, cleaned.split('.')[0] + suffix + '.arpassinfo') if self.writeTxtFile(path=path, text=str(dicConnect)): print '[Arsenal] ' + path + ' writed.' else: OpenMaya.MGlobal.displayError('[Arsenal] Can not write ' + path) return
objs = pm.ls(selection=True, transforms=True) self.exportFbx( objs ) pm.select( originalSelection) def exportAll(self): originalSelection = pm.ls(selection=True) ## Only attempt to export directly from transform nodes! objs = pm.ls( transforms=True ) self.exportFbx( objs ) pm.select( originalSelection) def exportFbx(self, objsOnWhichToAttemptExport): objsToExport = [] errors = [] for obj in objsOnWhichToAttemptExport: attr = getattr(obj, "mmmmExportFile", None) if attr: aVal = attr.get() if not aVal=="": objsToExport.append( obj ) else: print( "Export information on node not sufficient.") else: errors.append( "object" + obj.name() + " DID NOT have attr") for obj in objsToExport: pm.select( obj, replace=True) dirPathStr = getattr(obj,'mmmmExportPath').get() print( "dirPathStr: " + dirPathStr ) fnameStr = getattr(obj,'mmmmExportFile').get() dirPathStr = dirPathStr.replace( '\\', '/') print( "dirPathStr with replacement only: " ) print( "dirPathStr: " + dirPathStr ) if dirPathStr.endswith('/'): sep = '' else: sep = '/' isDirpathRelative = ( dirPathStr.startswith( './' ) or dirPathStr.startswith( '../' ) ) print( "dirPathStr before being changed: " ) print( "dirPathStr: " + dirPathStr ) if isDirpathRelative: workspacePathStr = self.getCurrentScenePath() print( "Exporting relative to: " + workspacePathStr ) dirPathStr = workspacePathStr + '/' + dirPathStr print( "workspacePathStr Exporting relative to: " + workspacePathStr ) print( "dirPathStr: " + dirPathStr ) dirPathAndFileAndExtStr = dirPathStr + sep + fnameStr print( "Attempting to export object: " + obj.name() ) print( "exporting to: " + dirPathAndFileAndExtStr ) pm.select(hierarchy=True) ## Load the Fbx Preset That should be used ## **** ideally, this should allow using a preset file in a relative folder ## currently just uses from MmmmTools presets folder ## should allow getting presets from elsewhere try: presetStrFromAttr = getattr(obj,'mmmmExportPreset').get() print( "mmmmExportPreset found preset string is: " + presetStrFromAttr ) if len(presetStrFromAttr)==0: msg = "Preset string is blank, using default preset instead" print( msg ) assert 1==msg ## this will fail forcing the except to run presetStr = self.getPreset(presetName = presetStrFromAttr) except: presetStr = self.getPreset() print( 'using preset: ' + presetStr ) cmd = 'FBXLoadExportPresetFile -f "' + presetStr + '";' print(cmd)
def exportFbx(self, objsOnWhichToAttemptExport): objsToExport = [] errors = [] for obj in objsOnWhichToAttemptExport: attr = getattr(obj, "mmmmExportFile", None) if attr: aVal = attr.get() if not aVal == "": objsToExport.append(obj) else: print("Export information on node not sufficient.") else: errors.append("object" + obj.name() + " DID NOT have attr") for obj in objsToExport: pm.select(obj, replace=True) dirPathStr = getattr(obj, 'mmmmExportPath').get() print("dirPathStr: " + dirPathStr) fnameStr = getattr(obj, 'mmmmExportFile').get() dirPathStr = dirPathStr.replace('\\', '/') print("dirPathStr with replacement only: ") print("dirPathStr: " + dirPathStr) if dirPathStr.endswith('/'): sep = '' else: sep = '/' isDirpathRelative = (dirPathStr.startswith('./') or dirPathStr.startswith('../')) print("dirPathStr before being changed: ") print("dirPathStr: " + dirPathStr) if isDirpathRelative: workspacePathStr = self.getCurrentScenePath() print("Exporting relative to: " + workspacePathStr) dirPathStr = workspacePathStr + '/' + dirPathStr print("workspacePathStr Exporting relative to: " + workspacePathStr) print("dirPathStr: " + dirPathStr) dirPathAndFileAndExtStr = dirPathStr + sep + fnameStr print("Attempting to export object: " + obj.name()) print("exporting to: " + dirPathAndFileAndExtStr) pm.select(hierarchy=True) ## Load the Fbx Preset That should be used ## **** ideally, this should allow using a preset file in a relative folder ## currently just uses from MmmmTools presets folder ## should allow getting presets from elsewhere try: presetStrFromAttr = getattr(obj, 'mmmmExportPreset').get() print("mmmmExportPreset found preset string is: " + presetStrFromAttr) if len(presetStrFromAttr) == 0: msg = "Preset string is blank, using default preset instead" print(msg) assert 1 == msg ## this will fail forcing the except to run presetStr = self.getPreset(presetName=presetStrFromAttr) except: presetStr = self.getPreset() print('using preset: ' + presetStr) cmd = 'FBXLoadExportPresetFile -f "' + presetStr + '";' print(cmd) pm.mel.eval(cmd) fname = dirPathAndFileAndExtStr #fname = cmds.file( location=True, query=True ) #fnameParts = fname.split('.') ## any string then .join will combine a list by the string before .join #fname = ".".join( fnameParts[0:-1] ) #ename = "__FORUDK.fbx" #fname = fname + ename pm.exportSelected( fname, shader=1, force=True, typ="FBX export", #pr = 1, ## #es = 1, )