Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
That's the exact code I already tried - I did a WinMerge file comparison to see if you'd made any subtle changes.
The minidom module seemed to be in the Poser 6 installation - the file minidom.py was under /Runtime/Pythom/lib/xml/dom/
Do you get the invalid escape message in Poser 7? (btw just noticed that all the backslashes were stripped out of the first post)
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).
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...
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).
Thanks again - I knew it was easy to do, but it's the sort of thing it would take me ages to actually find!
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).
Since Poser 6 seems to be the one that's causing most problems I should really just RTFM! So does P6 use Python 2.4.1, 2.4.2, 2.4.3 or 2.4.4? I've found the Python docs for all versions and want to bookmark the P6 one.
In fact a sticky thread on this forum with links to the appropriate Python Library Reference's for each Poser version would be very useful for people like me (and help avoid a lot of stupid questions!
Anyway, back to my file-handling queries - It's progressing well and successfully reading data from a CSV file (I abandoned the XML approach) into various lists and lists of lists. I've been using an absolute path for my data file, but I really want to use a relative path. The most logical location for the datafile is in the same folder as the script, i.e.
/Runtime/Python/poserScripts/3DCheapskate/
The following code seems to give me the correct filename when run from P6, P8 and P9 (I didn't use os.path.curdir since it doesn't won't work in P6) on a Windows 7 PC
import poser
import os
poserpath=os.path.split(poser.AppLocation())
print os.path.join(poserpath[0],'Runtime','Python','poserScripts','3DCheapskate','datafile.txt')
This should work on other versions of Windows, and on a MAC too, yes?
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).
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.
After doing a bit of reading up it seems that using the miniDOM module is a good way to start for parsing an XML file. It appears to be included in the Poser 6 runtime here...
E:e frontierPoser 6RuntimePythonlibxmldomminidom.py
Now I always like to start with a ready-made piece of code, and I found a nice simple miniDOM example in section 19.7.2. here http://docs.python.org/2/library/xml.dom.minidom.html
I just cut-and-pasted it into a test.py file on my desktop and ran it (File > Run Python Script...) from Poser 6.
ValueError: invalid x escape
Traceback (most recent call last):
File "", line 20, in ?
File "E:e frontierPoser 6RuntimePythonlibxmldomminidom.py", line 965, in parseString
return doparse(pulldom.parseString, args, kwargs)
File "E:e frontierPoser 6RuntimePythonlibxmldomminidom.py", line 951, in doparse
events = apply(func, args, kwargs)
File "E:e frontierPoser 6RuntimePythonlibxmldompulldom.py", line 340, in parseString
parser = xml.sax.make_parser()
File "E:e frontierPoser 6RuntimePythonlibxmlsax__init.py", line 81, in make_parser
return create_parser(parser_name)
File "E:e frontierPoser 6RuntimePythonlibxmlsax__init_.py", line 106, in _create_parser
return drv_module.create_parser()
AttributeError: 'module' object has no attribute 'create_parser'
If I add 'import poser' I get this:
ValueError: invalid x escape
Traceback (most recent call last):
File "", line 21, in ?
File "E:e frontierPoser 6RuntimePythonlibxmldomminidom.py", line 965, in parseString
return doparse(pulldom.parseString, args, kwargs)
File "E:e frontierPoser 6RuntimePythonlibxmldomminidom.py", line 951, in doparse
events = apply(func, args, kwargs)
File "E:e frontierPoser 6RuntimePythonlibxmldompulldom.py", line 340, in parseString
parser = xml.sax.make_parser()
File "E:e frontierPoser 6RuntimePythonlibxmlsax__init.py", line 93, in make_parser
raise SAXReaderNotAvailable("No parsers found", None)
xml.sax._exceptions.SAXReaderNotAvailable: No parsers found
But when I run it from Poser 9 it seems fine, although I still get that invalid x escape:
ValueError: invalid x escape
Demo slideshowSlide title
*...etc...*Can anybody tell me what's wrong in Poser 6?
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).