Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


structure posted Wed, 03 November 2021 at 2:59 AM Forum Coordinator

adp001 posted at 3:50 PM Tue, 2 November 2021 - #4429791

A shorter and less complicated version:


import os
import re

def get_library_pathes():
    version = int(poser.Version().split(".")[0])
    fname = os.path.join(os.environ["APPDATA"],
                         "Poser" if version < 11 else "Poser Pro", str(version),
                         "LibraryPrefs.xml")
    re_libs = re.compile(r"<ContentFolder.*?folder=\"([^\"]+)\"")
    with open(fname, "r") as fh:
        for line in fh:
            res = re.search(re_libs, line)
            if res:
                yield res.group(1)


if __name__ == "__main__":
    for entry in get_library_pathes():
        print(entry)

this line : 
    version = int(poser.Version().split(".")[0]) can be better written thus     
version = int(float(poser.Version())) and requires that poser or perhaps POSER_FAKE be imported.
better to include a dummy version function 
def Version():
    return 12 also this construct : 
    fname = os.path.join(os.environ["APPDATA"],
                         "Poser" if version < 11 else "Poser Pro", str(version),
                         "LibraryPrefs.xml") 

does not appear to working - I have set version to 12 - but it keeps using poser pro as the folder name .

    poserversion =  "Poser" if Version() < 11 else "Poser Pro"
    print(poserversion, Version()<11, Version())

output :
Poser Pro False 12

 


Locked Out