# Export to obj and reimport. In addition material collections for the objects # are saved and loaded to keep the material settings intact - so Poser 6+ only. # SAVE YOUR SCENE BEFORE RUNNING THIS SCRIPT! USE THIS SCRIPT ON A COPY OF YOUR # WORK! EVERY OBJECT OF THE SCENE WILL BE REPLACED BY A NEW OBJECT! # SAVE UNDER NEW FILENAME AFTER RUNNING THE SCRIPT! # Will export/import the current frame. # Feel free to improve the script, like making multiframe work :-) # - Dizzi #------------------------------------------------------------------------------- # and also set the temporary directory where the obj and mc6 are stored tempDir="C:\\temp\\" if poser.DialogSimple.YesNo("Really export everything in the scene to obj, delete it and reimport the obj?\n\nDid you save your scene?\n\nIs '"+tempDir+"' the correct temp path to export to?"): # nothing to do down here scene=poser.Scene() frameFrom=scene.Frame frameTo=scene.Frame multiframe=0 # Set Poser Frame Numbers (1-x) for start and endframe / doesn't work #frameFrom=3 #frameTo=4 #if (frameFrom-frameTo)==0: multiframe=1 global exportFigure global exportActor def CBFigure(actor): # The callback routine if actor.IsBodyPart()==1 and actor.ItsFigure().InternalName()==exportFigure.InternalName(): return 1 else: return 0 def CBActor(actor): # The callback routine if actor.InternalName()==exportActor.InternalName(): return 1 else: return 0 imExObject = scene.ImExporter() #scene.SetFrame(frameFrom) exoptions = imExObject.ExportOptions("obj", None) exoptions[poser.kExOptCodeUSEINTERNALNAMES] = 0 exoptions[poser.kExOptCodeFIRSTFRAME] = frameFrom exoptions[poser.kExOptCodeLASTFRAME] = frameTo exoptions[poser.kExOptCodeMULTIFRAME] = multiframe exoptions[poser.kExOptCodeWELDSEAMS] = 1 exoptions[poser.kExOptCodeASMORPHTARGET] = 0 exoptions[poser.kExOptCodeBODYPARTNAMESINPOLYGROUPS] = 0 exoptions[poser.kExOptCodeFIGNAMESINGROUPS] = 0 exoptions[poser.kExOptCodeEXISTINGGROUPSINPOLYGROUPS] = 0 imoptions = imExObject.ImportOptions("obj", None) imoptions[poser.kImOptCodeMAKEPOLYNORMSCONSISTENT] = 1 imoptions[poser.kImOptCodeOFFSETX] = 0.0 imoptions[poser.kImOptCodeOFFSETY] = 0.0 imoptions[poser.kImOptCodeOFFSETZ] = 0.0 imoptions[poser.kImOptCodeFLIPUTEXTCOORDS] = 0 imoptions[poser.kImOptCodeFLIPVTEXTCOORDS] = 0 imoptions[poser.kImOptCodeWELDIDENTICALVERTS] = 0 imoptions[poser.kImOptCodeCENTERED] = 0 imoptions[poser.kImOptCodePERCENTFIGSIZE] = 0.0 imoptions[poser.kImOptCodeFLIPNORMS] = 0 imoptions[poser.kImOptCodePLACEONFLOOR] = 0 print "Exporting and importing in Wavefront .obj format to "+tempDir+"..." for actor in scene.Actors(): if not (actor.IsBase() or actor.IsBodyPart() or actor.IsDeformer() or actor.IsZone() or actor.IsLight() or actor.IsCamera()) and actor.Name().count("Remote")==0 and actor.Name().count("CenterOfMass")==0 and not actor.Name()=='FocusDistanceControl' and not actor.Name()=='GROUND': exportActor=actor exportActorName=exportActor.Name() print '-exporting '+exportActorName # export prop and import again -- acts as unparent... imExObject.Export('obj', 'File Format Wavefront', tempDir+exportActorName+'.obj', exoptions, CBActor) for curMat in exportActor.Materials(): curMat.SetSelected(1) exportActor.SaveMaterialCollection(tempDir+exportActorName+'.mc6') try: print '--deleting original '+exportActorName exportActor.Delete() print '---importing '+exportActorName imExObject.Import('obj', 'File Format Wavefront', tempDir+exportActorName+'.obj', imoptions) newactor=scene.Actor(exportActorName) print '----loading mats for '+newactor.Name() newactor.LoadMaterialCollection(tempDir+exportActorName+'.mc6') except: print ('!error loading '+exportActorName+'.obj') for figure in scene.Figures(): exportFigure=figure print '-exporting '+exportFigure.Name() imExObject.Export('obj', 'File Format Wavefront', tempDir+figure.Name()+'.obj', exoptions, CBFigure) for curMat in figure.Materials(): curMat.SetSelected(1) figure.ParentActor().SaveMaterialCollection(tempDir+figure.Name()+'.mc6') print '--importing '+exportFigure.Name() imExObject.Import('obj', 'File Format Wavefront', tempDir+figure.Name()+'.obj', imoptions) newactor=scene.Actor(figure.Name()) newactor.LoadMaterialCollection(tempDir+figure.Name()+'.mc6') for figure in scene.Figures(): print '---deleting '+figure.Name() scene.SelectFigure(figure) scene.DeleteCurrentFigure() print 'Done!'