Forum: Poser Python Scripting


Subject: XML Parsing (miniDOM) In PoserPython - The Very, Very Basics... :o)

3dcheapskate opened this issue on Feb 15, 2013 · 9 posts


3dcheapskate posted Sun, 17 February 2013 at 1:06 AM

Thanks markschum - I don't know where the 'ValueError: invalid x escape' came from - it doesn't appear now.

:rolleyes: Must be finger trouble on my part - I'm getting a lot of that recently!

It still doesn't work in Poser 6 though - same errors as I mentioned in the first post, minus the invalid escape. So I think I'll sidestep this issue - a simple CSV file is probably all I need, something like this...

FigureName,yTran,zTran,Scale,xRot

Aiko 3,-0.068,-0.019,1.0,0
Apollo,-0.007,0.0,1.01,5.0

The basic reading of each line and extraction of the individual parameters is so simple, I don't recall why I ever considered XML!

f = open("C:/Users/Web/Desktop/FileReader/FileReader.txt")
try:
    for line in f:
        # Check first character of line for non-data lines
        if line[0] == '#':
            print "(COMMENT LINE) "+line
        elif len(line) == 1:
           print "(BLANK LINE) "+line
        else:
           listOfEntries=string.split(line,',')
           print "(DATA (by default) len="+str(len(line))+") "+listOfEntries[0] + ", Y translate=" + str(float(listOfEntries[1])) + ", Z translate=" + str(float(listOfEntries[2])) + ", Scale=" + str(float(listOfEntries[3])) + " X rotate=" + str(float(listOfEntries[4]))    
finally:
    f.close()

Note: I used the old-style file open/close as defined in section 2.7.3 here http://docs.python.org/2/library/stdtypes.html#file-objects) so it'll work in Poser 6. And I'm aware that 'split()' is deprecated but, hey!, it works (in both Poser 6 and Poser 9)!

Of course the code needs to check that data lines are valid, but I think I'll go this way instead and forget about XML.


The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.

*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).