Forum: Poser Python Scripting


Subject: Export object file size is zero

Tekitoumen opened this issue on Aug 23, 2022 ยท 8 posts


Tekitoumen posted Tue, 23 August 2022 at 3:21 AM

Hello, 

Please excuse me for asking this same question.

https://www.renderosity.com/forums/threads/2972673/export-by-python


If you know a solution please let me know...

As I wrote in "export-by-python", import the obj model from python, and  export the model from python  in obj format.

Then the size of the obj file created will be 0 bytes.

Just an import or just an export will succeed.

I don't know what is wrong. . .

If you have any advice, could you tell me.


Thank you.


----------------------------------------------------------------------------------------

import poser 


def importOBJ(pathname): 

    imExObject = scene.ImExporter() 

    imoptions = imExObject.ImportOptions("obj", None) 

    

    # Set the OBJ import options

    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] = 1 

    imoptions[poser.kImOptCodeCENTERED] = 0 

    imoptions[poser.kImOptCodePERCENTFIGSIZE] = -1 

    imoptions[poser.kImOptCodeFLIPNORMS] = 0 

    imoptions[poser.kImOptCodePLACEONFLOOR] = 0 

    

    try: 

        #imExObject.Import('obj', 'File Format Wavefront', objectPath, imoptions)

        imExObject.Import('obj', 'File Format Wavefront', pathname, imoptions) 

    except: 

        print ("OBJ failed to import.") 



def exportOBJ(pathname, file_name): 

    print(pathname)

    print(file_name)


    global actList 

    # define the file path

    objectPath = os.path.join(pathname,file_name) 

    imExObject = scene.ImExporter() 

    exoptions = imExObject.ExportOptions("obj", None) 

 

    # Set the OBJ export options

    exoptions[poser.kExOptCodeUSEINTERNALNAMES] = 0 

    exoptions[poser.kExOptCodeFIRSTFRAME] = 0 

    exoptions[poser.kExOptCodeLASTFRAME] = 29 

    exoptions[poser.kExOptCodeMULTIFRAME] = 0 

    exoptions[poser.kExOptCodeWELDSEAMS] = 1 

    exoptions[poser.kExOptCodeASMORPHTARGET] = 0 

    exoptions[poser.kExOptCodeBODYPARTNAMESINPOLYGROUPS] = 1

    exoptions[poser.kExOptCodeFIGNAMESINGROUPS] = 0 

    exoptions[poser.kExOptCodeEXISTINGGROUPSINPOLYGROUPS] = 1 

 

    try: 

        imExObject.Export('obj', 'File Format Wavefront', objectPath, exoptions, sceneSelectionCallback) 

        #imExObject.Export('obj', 'File Format Wavefront', objectPath, exoptions, none) 

        print ("Sucessfully exported %s" % actList )

    except: 

        print ("OBJ failed to export.")


# callback to check which actor(s) are to be exported

def sceneSelectionCallback(CB): 

    global actList 

    for act in actList: 

        if act.InternalName() == CB.InternalName(): 

            include = 1 

            return include 

        else: 

            include = 0 

            return include 

 

# define what you want exported. For this example I'll 

# just include the actor currently selected in the scene 

# plus the GROUND

actList = [scene.CurrentActor(),scene.ActorByInternalName("GROUND")] 

# go do it


---in  main-----

importOBJ("import_path")


actor = scene.Actor("target_name") 

scene.SelectActor(actor) 

 scene.DrawAll()


exportOBJ("export_path", "obj file name")