Forum: Poser Python Scripting


Subject: Library load methods

EnglishBob opened this issue on Mar 20, 2014 · 9 posts


structure posted Sat, 29 March 2014 at 9:38 AM Forum Coordinator

updated script - this appears to be working correctly

import poser, os, os.path, string
#    Set Variables
scene=poser.Scene()
path=None
libs=['camera','character','face','hair','hand','light','pose','props','materials']
ext={0:'.cm%s',1:'.cr%s',2:'.fc%s',3:'.hr%s',4:'.hd%s',5:'.lt%s',6:'.pz%s',7:'.pp%s',8:'.mc%s',9:'.mt%s'} #,'.png','.rsr'}
s=['2','3','5','6','z']

#    Select Folder
def GetWorkingFolder(link):
    parentDialog=0
    message='Select Folder'
    Dir=os.path.join(poser.Libraries()[0], 'Runtime')
    startDir=os.path.join(Dir,'Libraries', link)
    wDir=poser.DialogDirChooser(parentDialog,message,startDir)
    wDir.Show()
    WorkingFolder=wDir.Path()
    
    return WorkingFolder

#    what to do with what we found ?
def DoSomething(item, c):
    if c==9:c=8
    print 't',item, c, libs[c]
    
#    create Choice Dialog
link=poser.DialogSimple.AskMenu("Choose :","Which Library ?",libs)

#    find the correct starting folder
for l in libs:
    if not link == None:
        if l == link:
            path = GetWorkingFolder(l)

#    discover files
if not path == None:
    items=os.listdir(path)
    for item in items:
        c=0
        for i in ext:
            t=0
            for a in range(len(s)):
                try:
                    if c==9 : c-8
                    if item.endswith(ext[c] %s[t]):
                         DoSomething(item, c)
                except:
                    pass
                t+=1
            c+=1

Locked Out