Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


EVargas posted Sat, 23 April 2022 at 7:42 PM

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()



Store | Website