Forum: Poser Python Scripting


Subject: How to fetch the full os.path of a CurrentFigure ?

HartyBart opened this issue on Dec 27, 2020 ยท 27 posts


structure posted Sun, 27 December 2020 at 4:17 PM Forum Coordinator

something like this might work for creating your index


import json
import os.path
import poser

class _data_class:
    def save_data( self, file, db ):
        if file:
            if len( db )>0:
                with open( file, 'w') as f:
                    json.dump( db, f, indent=2 ) 

    def load_data( self, file ):
        if file:
            try:
                with open( file, 'r' ) as f:
                    return json.load( f )
            except:
                return None

exts = ( ".cr2",".crz" )
cross_ref_Dict = {}

for library in poser.Libraries():
    library = os.path.join( library, "Runtime", "Libraries" )
    for root, folders, files in os.walk( library ):
        for file in files:
            file = os.path.join( root, file ) 
            if "Character" in file.title():
                if file.endswith( exts ):
                    path1 = file
                    path2 = os.path.dirname(file.replace( "character".title(), "Pose" ))
                    alias = os.path.splitext(os.path.basename( file ))[0]
                    if alias and path1 and path2:
                        if not alias in list( cross_ref_Dict.keys() ):
                            cross_ref_Dict.update( { alias : (path1, path2) } )

if len(cross_ref_Dict.keys()) > 0:
    _data_class().save_data( database_filepath, cross_ref_Dict )

if os.path.exists( database_filepath ):
    cross_ref_Dict = _dataclass().load_data( database_filepath )

if len( cross_ref_Dict.keys() ) > 0:
    for key in cross_ref_Dict.keys():
        print( key, cross_ref_Dict[key] )

Locked Out