import poser, os, string, shutil, sys, math maps = [] fails = [] #SM def appendTexture(actor): #SM global maps try: materials = actor.Materials() for material in materials: try: for node in material.ShaderTree().Nodes(): if node.Type() == poser.kNodeTypeCodeIMAGEMAP or node.Type() == poser.kNodeTypeCodeMOVIE: inp = node.Input(0) if inp.Type() == poser.kNodeInputCodeSTRING: val = inp.Value() if val != None and val!= "None": help = os.path.dirname(poser.AppLocation()) val = os.path.join(help, val) if not val in maps: if not os.path.exists(val): fails.append(val) poser.Scene().SelectActor(actor) node.SetPreviewCollapsed(1) material.ShaderTree().UpdatePreview() val = os.path.join(help, inp.Value()) maps.append(val) except: print "Could not locate the texture map of the material: " + material.Name() except: a=1 #SM def getFiles(): scene = poser.Scene() for figure in scene.Figures(): appendTexture(figure) for actor in figure.Actors(): appendTexture(actor) for actor in scene.Actors(): appendTexture(actor) #3DO scene = poser.Scene() #3DO def exScene (basefilename): #3DO scene = poser.Scene() imExScene = scene.ImExporter() exopt = imExScene.ExportOptions("obj", None) exopt[poser.kExOptCodeUSEINTERNALNAMES] = 0 exopt[poser.kExOptCodeMULTIFRAME] = 0 exopt[poser.kExOptCodeFIRSTFRAME] = 0 exopt[poser.kExOptCodeLASTFRAME] = 0 exopt[poser.kExOptCodeBODYPARTNAMESINPOLYGROUPS] = 0 exopt[poser.kExOptCodeWELDSEAMS] = 0 exopt[poser.kExOptCodeASMORPHTARGET] = 0 exopt[poser.kExOptCodeFIGNAMESINGROUPS] = 0 exopt[poser.kExOptCodeEXISTINGGROUPSINPOLYGROUPS] = 0 imExScene.Export('obj', 'File Format Wavefront', basefilename+'.obj', exopt) #3DO def getCurrentCamera(): #3DO Camera settings and scene resolution curCam = poser.Scene().CurrentCamera() #initialize variable and get camera displacement from origin location x=0.0 y=0.0 z=0.0 print "LocalDisplacement (x,y,z):" a = curCam.LocalDisplacement(x,y,z) print a[0] print a[1] print a[2] #Switch Y and Z Translate and Rotate global blndrCamXTrans blndrCamXTrans = a[0] * 4.8768 global blndrCamZTrans blndrCamZTrans = a[1] * 4.8768 global blndrCamYTrans blndrCamYTrans = 0.0 - (a[2] * 4.8768) global blndrCamXRot blndrCamXRot = curCam.ParameterByCode(poser.kParmCodeXROT).Value() + 90 global blndrCamZRot blndrCamZRot = curCam.ParameterByCode(poser.kParmCodeYROT).Value() global blndrCamYRot blndrCamYRot = 0 - curCam.ParameterByCode(poser.kParmCodeZROT).Value() global blndrCamFL blndrCamFL = curCam.ParameterByCode(poser.kParmCodeFOCAL).Value() global scnHorX global scnVerY print "OutpuRes (x,y):" b = poser.Scene().OutputRes(x,y) print b[0] print b[1] scnHorX = b[0] scnVerY = b[1] #3DO def getPath(): #3DO #Create File Dialog diaFile = poser.DialogFileChooser(2) #Show dialog, and get path and extension if (diaFile.Show()): path = diaFile.Path() file, exten = os.path.splitext(diaFile.Path()) #If they added an extension, then only use path with filename (not ext) part for path if (string.lower(exten) == ".obj"): path = file #dir is path minus filename dir = os.path.dirname(path) #assume dir exists since they just used it, but check anyway and then return results if os.path.exists(dir): return (path, dir) return (None, None) #3DO def MakePythonFile(file_name): #3DO new routine to make python file print 'Make Python File started.' temp_path = dst + file_name file = open(temp_path, 'w') print blndrCamXTrans print blndrCamYTrans print blndrCamZTrans print blndrCamXRot print blndrCamYRot print blndrCamZRot #print bCamFoc fileData = """import mcjBlendBot, bpy mcjBlendBot.setGloss( 0.05, 0.15 ) mcjBlendBot.setRenderEngine( "CYCLES" ) mcjBlendBot.setImageSize( """ + str(scnHorX) + """,""" + str(scnVerY) + """) mcjBlendBot.setCyclesSettings( "EXPERIMENTAL", "GPU", "CUDA", 100 ) mcjBlendBot.setSmooth( True ) mcjBlendBot.setEdgeSplit( True ) mcjBlendBot.addCamera( """ + str(blndrCamXTrans) + """, """ + str(blndrCamYTrans) + """, """ + str(blndrCamZTrans) + """, """ + str(blndrCamXRot) + """, """ + str(blndrCamYRot) + """, """ + str(blndrCamZRot) + """, """ + str(blndrCamFL) + """ ) mcjBlendBot.loadfix( "REPLACETHIS", "CYCLESMATS", "", True ) mcjBlendBot.setHorizonColor( 0.47637062668204533, 0.5968319876970396, 1, 1.0 ) ob = bpy.data.objects.get(\"""" + onlyName + """\") ob.select = True bpy.context.scene.objects.active = ob ob.scale=((4.8768,4.8768,4.8768))""" #3DO Insert Path into above Batch File fileData = fileData.replace("REPLACETHIS",dst + objFile) #3DO Change backslashes to forward slashes for Blender Python fileData = fileData.replace("\\","/") file.write(fileData) file.close() print 'Make Python File completed.' #3DO def MakeBatchFile(file_name): #3DO new routine to make a batch file print 'Make Batch File started.' temp_path = dst + '/' + file_name file = open(temp_path, 'w') fileData = '"' + blenderLoc + '"' + ' -P ' + '"' + dst + pyFile + '"' #3DO Change backslashes to forward slashes for Blender Python fileData = fileData.replace("\\","/") print fileData file.write(fileData) file.close() print 'Make Batch File completed.' #3DO Editable Blender location blenderLoc = "C:/Program Files/Blender Foundation/Blender/blender.exe" #3DO fileName is path plus filename, dst is path only without ending slash fileName, dst = getPath() #3DO create new sub-directory from obj name and put all in there onlyName = fileName.replace(dst,"") dst = fileName fileName = dst + onlyName os.makedirs(dst) print "New Path: " + dst print "New Filename: " + fileName onlyName = onlyName.replace("\\","") print onlyName #3DO exScene(fileName) getFiles() print 'Done get files' #3DO Copy Maps to the new directory location for mapObj in maps: mapName = os.path.basename(mapObj) path1,file1=os.path.split(mapObj) print 'file1:' print file1 print 'path1:' print path1 if file1 != "": shutil.copy(mapObj,dst) print mapName print 'completed copy maps' #3DO get just filenames with pre slashes print '3DO get just filenames with pre slashes' objFile = fileName.replace(dst,"").strip() + '.obj' pyFile = fileName.replace(dst,"").strip() + '.py' batchFile = fileName.replace(dst,"").strip() + '.bat' #3DO Call routine to get camera settings and render size print '3DO Call routine to get camera settings and render size' getCurrentCamera() #3DO makes files print 'About to make python file' MakePythonFile(pyFile) print 'Done python file, making batch file' MakeBatchFile(batchFile) print 'Done batch file' #3DO Run the batch file runBat = dst + batchFile print "About to run " + runBat #3DO os.system just popped up a cmd window and disappeared...popen worked. from subprocess import Popen Popen(runBat, cwd=dst) #3DO print "Script is complete"