Forum: Poser Python Scripting


Subject: Useful Code Snippets

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


structure posted Mon, 25 April 2022 at 9:09 AM Forum Coordinator

evargas posted at 11:53 AM Sun, 24 April 2022 - #4437678

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


nice addition - thanks

a slightly shorter version

import poser
# -- -- -- -- -- (un)Lock_Current_Cam.py -- -- -- -- --

scene = poser.Scene()
cam = scene.CurrentCamera()

def lockCurrentCam(lock = True, camPar = None):
    for parName in ('xtran','ytran','ztran','xrot','yrot','zrot'):
        if lock:
            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)
        else:
            camPar = cam.Parameter(parName)
            camPar.SetMinValue(-10000)
            camPar.SetMaxValue(10000)
            camPar.SetForceLimits(0)
    return True if camPar.ForceLimits()==1 else False
           

camlocked = lockCurrentCam() # Lock the cam
camlocked = lockCurrentCam(False) # unlock the cam

Locked Out