Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Dec 02 3:16 pm)
Thank you for your reply.
When I checked the return value of Callback, it was not "True".
After checking, it seems that the cause was bad timing to create actList. (I was generating the actList before the import completed)
Also, thanks for pointing out about the "==".
Thanks to you, I was able to solve the problem.
Thank you for your kindness.
Tekitoumen posted at 7:12 PM Tue, 23 August 2022 - #4443226
Also, thanks for pointing out about the "==".A word of warning:
Using "in" instead of "==" can quickly become a massive problem. Why?
"" in "any string" == True
That' s why.
An empty string is contained in any valid string.
If you absolutely want to use "in" instead of "==", then this is how:
string_A = "any"
string_B = "any string"
len(string_A) > 0 and string_A in string_B == True
string_A = ""
len(string_A) > 0 and string_A in string_B == False
But.... if string_A is None then a Type Error is raised. But this also happens with a regular comparison with "==". So I leave it at that.
However, what I do from time to time is to use a function:
def str_eq(sa: str, sb: str) -> bool:
return sa == sb or sa in sb if sa is not None and sb is not None and len(sa) > 0 else False
(Python 3)
The function first tries a standard comparison with "==". Only if this fails, a test with "in" is performed. In addition, the two variables passed (sa and sb) are tested for None.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
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")