Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Mar 19 1:03 pm)
adp001 posted at 3:16 AM Wed, 3 November 2021 - #4429836
that works fine thank youMaybe this one is more robust:
fname = os.path.join(os.environ["APPDATA"], "Poser", str(version), "LibraryPrefs.xml")
if not os.path.exists(fname):
fname.replace("Poser", "Poser Pro")
How do we take into account, poser builds from 11.2 and poser builds past 12 - right now this is adequate for my needs, but do we just update it for every build?
do remember to edit the line
fname.replace("Poser", "Poser Pro")
to read
Locked Out
How do we take into account, poser builds from 11.2 and poser builds past 12 - right now this is adequate for my needs, but do we just update it for every build?
Since we can't guess which scheme Bondware will follow for the version numbers and the resulting file structure, there is nothing left to do but wait until the case occurs that it doesn't work as it is anymore :)
right - this would be a better methodIn my opinion, a version number should not be assumed to be a float. Version numbers can also look like this: "12.3.0.3". This is where "float" fails severely.
My method is something like Python's "sys.version_info.major", where Python's version number contains several decimal points.
Locked Out
do remember to edit the line
fname.replace("Poser", "Poser Pro") to readfname = fname.replace("Poser", "Poser Pro")
Ups!
Maybe post a complete and tested version. I'm working out of the blue at the moment because I don't have a working Poser version here anymore.tested and working :
Locked Out
class ignore_error(object):
def __init__(self, *args):
self.tolerable = args
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else True
with ignore_error(NameError, poser.error):
actor = poser.Scene().Actor("not existing actor")
Made a mistake in:
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else True
the default result must be False, not True:
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else False
adp001 posted at 2:49 AM Wed, 3 November 2021 - #4429830
class ignore_error(object):
def __init__(self, *args):
self.tolerable = args
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else True
with ignore_error(NameError, poser.error):
actor = poser.Scene().Actor("not existing actor")
Made a mistake in:
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else Truethe default result must be False, not True:
def __exit__(self, exc_type, exc_val, exc_tb):
return exc_type in self.tolerable if len(self.tolerable) else False
nice addition, this could be used in conjunction with contextlib.suppress
which captures all kinds of errors and ignores them.
in this simple example, I am trying to print a non-digit string as an integer,
and the output is suppressed.
without the contextlib.suppress in place the output is
TypeError: nothing to see here, move along is invalid
In the following amended example the output is printed as
nothing to see here, move along
I am unsure that I have found every type of python error, but here is an
almost comprehensive list of errors that contextlib.suppress can capture.
Locked Out
Get poser AppLocation outside of poser ( WINDOWS ONLY ) (you need to add this to POSER_FAKE by adp001, a separate file would be the best option probably. e.g. in the poser fake folder, add Applocation.py)
Locked Out
get poser templocation / prefslocation outside of poser (you need to add these to POSER_FAKE by adp001, separate files would be the best option probably. e.g. in the poser fake folder, add Templocation.py and PrefsLocation.py)
Locked Out
nice addition, this could be used in conjunction with contextlib.suppress
which captures all kinds of errors and ignores them.
"contextlib.suppress" is not present in Python 2.7. And 2.7 is currently much more important than Python 3, because Poser 12 is only used by a few people.
Code that runs only under Python 3 should be explicitly marked. Otherwise beginners look for supposed errors where there are none.
Function to trim/extend array, tuple, bytes or string to a fixed number of elements:
def trimmed(arg, nr_of_elements, f=None):
return (arg + arg.__class__([f, ] * nr_of_elements)
if isinstance(arg, (tuple, list))
else (arg + arg.__class__((f or " ") * nr_of_elements)
if isinstance(arg, (str, bytes))
else [arg, ] + [f, ] * nr_of_elements))[:nr_of_elements]
("f" is what is used to fill missed elements; should be compatible with 'arg')
trimmed([1,2,3], 5) # returns list: [1, 2, 3, None, None]
trimmed((1,2,3), 5) # returns tuple: (1, 2, 3, None, None)
trimmed([1, 2, 3, 4, 5, 6, 7, 8, 9], 5) # returns list: [1, 2, 3, 4, 5]
trimmed("Sample", 10, ".") # returns string: "Sample...."
trimmed(b'123', 5, b'.') # returns bytes: b'123..'
trimmed(10, 5, 1) # returns [10, 1, 1, 1, 1]
trimmed(10, 5, [1, 2, 3]) # returns [10, [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]
trimmed([], 5, 1) # returns list: [1, 1, 1, 1, 1]
trimmed((), 5, 1) # returns tuple: (1, 1, 1, 1, 1)
I don't know if this can help someone, but just in case...
These last months, I've been writing a toolbox with a few wxpython script to import, as the main script has more than 1100 lines. The problem with python is that once a module is imported, it remains in memory, and I've been searching a way to pop it out if there's an error in it, hence this method (I'm writing for Poser12):
import sys
try: sys.modules.pop('my_module')
except: pass
from my_module import MyClass
PhYl.
Win10 on i7 8700K@4.3Ghz, 64Gb, Asus TUF Gaming RTX 4070 OC Edition, 2x 2Tb ssd + 6+4Tb hd + 1x 8Tb hd + 1 10T NAS, Poser 11, Poser 12 and now Poser 13
Y-Phil posted at 12:46 PM Wed, 29 December 2021 - #4432576
I don't know if this can help someone, but just in case...
These last months, I've been writing a toolbox with a few wxpython script to import, as the main script has more than 1100 lines. The problem with python is that once a module is imported, it remains in memory, and I've been searching a way to pop it out if there's an error in it, hence this method (I'm writing for Poser12):
Locked Out
Well... Thank you for that nice trick! 😁Y-Phil posted at 12:46 PM Wed, 29 December 2021 - #4432576
I don't know if this can help someone, but just in case...
These last months, I've been writing a toolbox with a few wxpython script to import, as the main script has more than 1100 lines. The problem with python is that once a module is imported, it remains in memory, and I've been searching a way to pop it out if there's an error in it, hence this method (I'm writing for Poser12):import systry: sys.modules.pop('my_module')except: passfrom my_module import MyClass
nice, there is also another method :
import importlibimport moduleimportlib.reload(module)
PhYl.
Win10 on i7 8700K@4.3Ghz, 64Gb, Asus TUF Gaming RTX 4070 OC Edition, 2x 2Tb ssd + 6+4Tb hd + 1x 8Tb hd + 1 10T NAS, Poser 11, Poser 12 and now Poser 13
Locked Out
Convert bytes to Kb, Mb, Gb, or Tb
Locked Out
convert a string of digits to numeric and remove even or odd numbers
Locked Out
Install a missing module from inside a running python script, and rerun the script (using rich as an example )
Locked Out
Hi guys, so here I go again trying to share something, hopefully not reinventing the wheel.
While learning (or trying) to use HDRI and setup scenes with cameras from multiple angles etc, I found myself accidentally moving the cameras a lot. I don't like saving cameras to the library, and I always missed a way to quickly lock/unlock its position/rotation. The native "object/lock" menu can do this, but the camera have to be selected in order for it to work. I want to simply lock/unlock the current ACTIVE camera, without worrying about selecting it in a list.
I searched G00gle and here but with no success I decided to go for it and, why not, learn some more python along the way. Here I share a few lines that help me a lot. These are two separate files that can be added to the python scripts window, or put in "(...)/Poser Software/Poser 12/Runtime/Python/poserScripts/ScriptsMenu/"
For some reason this only works with the user created cameras ("object/create camera"), but I don't bother with it since I always create a new camera for rendering anyway.
# Lock_Current_Cam.py
scene = poser.Scene()
cam = scene.CurrentCamera()
def lockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(camPar.MinValue() - 1 * camPar.MinValue() + camPar.Value())
camPar.SetMaxValue(camPar.MaxValue() - 1 * camPar.MaxValue() + camPar.Value())
lockCurrentCam()
# ---------------------------------------
# Unlock_Current_Cam.py
scene = poser.Scene()
cam = scene.CurrentCamera()
def unlockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(-10000)
camPar.SetMaxValue(10000)
unlockCurrentCam()
"Art exists so that reality does not destroy us" - Friedrich Nietzsche
Update here, when translating to the "def" syntax I forgot the "Force Limits", fixed below. Another good tip is to set a keyboard shortcut for both, it makes life a lot easier!
# -- -- -- -- -- Lock_Current_Cam.py -- -- -- -- --
scene = poser.Scene()
cam = scene.CurrentCamera()
def lockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(camPar.MinValue() - 1 * camPar.MinValue() + camPar.Value())
camPar.SetMaxValue(camPar.MaxValue() - 1 * camPar.MaxValue() + camPar.Value())
camPar.SetForceLimits(1)
lockCurrentCam()
# -- -- -- -- -- Unlock_Current_Cam.py -- -- -- -- --
scene = poser.Scene()
cam = scene.CurrentCamera()
def unlockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(-10000)
camPar.SetMaxValue(10000)
camPar.SetForceLimits(0)
unlockCurrentCam()
"Art exists so that reality does not destroy us" - Friedrich Nietzsche
evargas posted at 11:53 AM Sun, 24 April 2022 - #4437678
nice addition - thanksUpdate here, when translating to the "def" syntax I forgot the "Force Limits", fixed below. Another good tip is to set a keyboard shortcut for both, it makes life a lot easier!
# -- -- -- -- -- Lock_Current_Cam.py -- -- -- -- --
scene = poser.Scene()
cam = scene.CurrentCamera()
def lockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(camPar.MinValue() - 1 * camPar.MinValue() + camPar.Value())
camPar.SetMaxValue(camPar.MaxValue() - 1 * camPar.MaxValue() + camPar.Value())
camPar.SetForceLimits(1)
lockCurrentCam()
# -- -- -- -- -- Unlock_Current_Cam.py -- -- -- -- --scene = poser.Scene()
cam = scene.CurrentCamera()
def unlockCurrentCam():
for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
camPar = cam.Parameter(parName)
camPar.SetMinValue(-10000)
camPar.SetMaxValue(10000)
camPar.SetForceLimits(0)
unlockCurrentCam()
Locked Out
Locked Out
number outside chosen range? select the closest viable number to the chosen number.
Output :
Locked Out
get screen resolution
Locked Out
Mirror / reverse data:
INSTANCES for testing what your variable is. ( this is just for printing headings )
Locked Out
Just for the records:
Python sets and dictionaries are unordered. So not sorted. For this reason there is no "reverse" for it. Because the order is random.
https://docs.python.org/3.8/library/stdtypes.html#set-types-set-frozenset
Exception for dictionaries: Class OrderedDict from lib collections.
in python 3 - reversing "ABRACDABRA"
returns : ARBADCARBA
Dictionaries are ordered and so can be reversed as is evidenced by
Locked Out
creating a class for working with colors: (part I)
Locked Out
Toggle lock keys * WINDOWS
importable script: ( I saved this in lib/site-packages under folder _toggle_keys)
Locked Out
getting single characters from keystrokes and building a string from them * WINDOWS
Locked Out
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.
Maybe this one is more robust: