Forum: Poser Python Scripting


Subject: Is there any way to know if a figure is hair?

maur_2005 opened this issue on Oct 13, 2021 ยท 14 posts


structure posted Fri, 15 October 2021 at 3:02 PM Forum Coordinator

afaik, it is not possible to change the internal name. However, you could change the external name with a script, combing through the folder would work with hr2 files but not with pp2 or cr2 unless there is an obvious way to tell them apart from a coat or a hat.

Or you could write a script which could ask the user for each item it finds whether it  is hair or not. 
my approach would be to build a user editable database. 

import os
import poser
import wx

extensions = ( ".hr2", ".hrz" )
prefslocation = poser.PrefsLocation()
dbfile = os.path.join( prefslocation, "hairdb", "hairdb.txt" )
if not os.path.exists( os.path.dirname( dbfile ) ):
    os.makedirs( os.path.dirname( dbfile ) )
    with open( dbfile, "w" ) as writefile:
        writefile.write("")

# create hair database
libraries = poser.Libraries()
for library in libraries:
    hairlibrary = os.path.join( library, "Runtime", "Library", "Hair" )
    for root, folders, files in os.walk( hairlibrary ):
        for file in files:
            if file.endswith( extensions ):
                file = os.path.join( root, file )
                with open( file, "r" ) as readfile:
                    lines = readfile.readlines()
                for line in lines:
                    if line.startswith( "   name" ):
                        line = line.strip()
                        line = line.replace( "name".casefold(), "" )
                        break
                with open( file, "a" ) as appendfile:
                    appendfile.write( line + "\n" )


This way, you can then write a script which accesses the database to see if any object in the scene is a recognised hair. 
Obviously any hair pp2 or cr2 would likely need to be added manually or with a combing script that allows the user to select which objects are hair and which are not. 

Locked Out