Tue, Nov 19, 7:45 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Library load methods


EnglishBob ( ) posted Thu, 20 March 2014 at 5:25 AM · edited Tue, 19 November 2024 at 7:26 AM

I'm trying to devise a script that will let me browse for and load any library file.

I can use LoadLibraryFigure( path ) to load any sort of geometry-based content: figures, props or hair. So far, so good.

Contrary to what I've read elsewhere, I seem to have to use the correct specific method for modifier types: LoadLibraryPose for poses, LoadLibraryLight for lights and so on, although I haven't tested every permutation yet. If this is true, then I should add some code to detect the file extension that I choose and switch to using the right load method - but if you know a better way, please let me know!

A bigger problem, in Poser 7 anyway, is that there isn't a LoadLibraryMaterial method - or is there? It isn't in the Python Methods manual. I tried

scene.LoadLibraryMaterial( path )

but it didn't do anything. However there wasn't a syntax error either, so maybe the method exists but is broken?


EnglishBob ( ) posted Thu, 20 March 2014 at 5:35 AM

Quote - ...there isn't a LoadLibraryMaterial method - or is there?

Ah, found it. I need LoadMaterialSet or LoadMaterialCollection. Naming conventions - who needs 'em? :)

I can probably take it from here by ploughing through a big elif structure, but do chime in with hints 'n' tips if you have them.  

 


structure ( ) posted Thu, 20 March 2014 at 7:32 AM · edited Thu, 20 March 2014 at 7:35 AM
Forum Coordinator

this is something I am still working on - but you may be able to use it for what you need

'''coded by structure'''
#----------------------#
#    imports
import poser, os, os.path
#    set Variables
scene=poser.Scene()
#    dictionaries and lists
suflist = {    0    :    '.cr%s',
            1    :    '.pz%s',
            2    :    '.fc%s',
            3    :    '.hr%s',
            4    :    '.hd%s',
            6    :    '.lt%s',
            7    :    '.cm%s',
            8    :    '.mt%s',
            9    :    '.mc%s',
            10    :    '.pz%s',
            11    :    '.pp%s'}
s=[2,3,5,6,'z']
library = ['Character','Pose','Face','Hair','Hand','light','Camera','Material','Material','Scene','Props']
#    functions
def DoSomething(item, c):
    folder = os.path.join(poser.Libraries()[0], 'runtime','Libraries',library[c])
    print folder

#    main

item = 'material.pp2'
c=0
for i in suflist:
    t=0
    for a in range(len(s)):
        try:
            if item.endswith(suflist[c] %s[t]):
                print suflist[c] %s[t], c
                 DoSomething(item, c)
        except:
            pass
        t+=1
    c+=1

Locked Out


EnglishBob ( ) posted Thu, 20 March 2014 at 7:37 AM · edited Thu, 20 March 2014 at 7:45 AM

Thanks, that looks like an elegant way of dealing with the Poser library file types. I'll reflect on it in due course.

A little more on the project - it seems that although LoadLibraryFigure() will indeed load any object, it doesn't pass through parenting information from smart props or hair, nor does it replace existing hair. I guess I should use the specific load method for each one to get those behaviours.


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


EnglishBob ( ) posted Sat, 29 March 2014 at 11:28 AM

Thanks! I'm away from home at present, so I'll study that on my return.

Meantime, I pulled apart Tromnek's PRPC code and cobbled together something that works, at least.  


markschum ( ) posted Mon, 31 March 2014 at 7:58 PM

Have you cosidered using the file dialog to select a file and then a stack of

 

if (filename[-3:]  == "cr2") or (filename[-3:] == "crz"0 :

     loadlibraryfigure(... )

etc

 

its tedious to code but a few copy paste and edit and your done.


EnglishBob ( ) posted Tue, 01 April 2014 at 4:47 AM

That's exactly what I did, Mark, thanks... ;)

I'll see about posting my script if there's any interest in it. I only need it because my Poser uage is a little - peculiar - and I'm not referring to the artwork. Although that is peculiar, too. ;)  


markschum ( ) posted Wed, 02 April 2014 at 5:35 PM

markschum stating the obvious since 2004  :woot:


Privacy Notice

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.