Forum: Poser Python Scripting


Subject: Useful Code Snippets

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


structure posted Sun, 19 July 2020 at 9:47 PM Forum Coordinator

Updated version of the above code

# -*- coding: utf-8 -*- 
# Change Shadow Intensity of Selected Lights

import poser
import wx
scene = poser.Scene()
title = "Shadow Intensity Editor"

def chooselights( title = "", prompt = "", OptionList = [], parent = None ):
    if OptionList == []: return False
    dialog = wx.MultiChoiceDialog( parent, prompt, title, OptionList )

    if dialog.ShowModal() == wx.ID_OK:
        selections = dialog.GetSelections()
        strings = [OptionList[x] for x in selections]
        if selections == []:
            selections = False
        return ( selections )

    else:
        return ( False )
    
    dialog.Destroy()

def gettextentry( title = "", message = "", parent = None ):

    TE_dialog = wx.TextEntryDialog( parent, message, title, "", style=wx.OK)
    TE_dialog.SetValue("")

    return TE_dialog.GetValue() if TE_dialog.ShowModal() == wx.ID_OK else False

def okcancel( title = "", alertmessage = "", okonly = False, parent = None ):

    if okonly:
        style = ( wx.OK|wx.ICON_INFORMATION|wx.STAY_ON_TOP )
    else:
        style = ( wx.OK|wx.CANCEL|wx.ICON_INFORMATION|wx.STAY_ON_TOP )      

    ok_dialog = wx.MessageDialog( parent, alertmessage, title, style )
    
    return True if ok_dialog.ShowModal() == wx.ID_OK else False

lights = []

for light in scene.Lights():
    lights.append( light.Name() )

lights = chooselights( title, "Please select which lights to edit.", lights )
if lights:
    try:
        value = float( gettextentry( title, "Please enter your value ( 0 - 1 )" ) )
    except:
        value = 0

    for light in lights:
        scene.Lights()[light].ParameterByCode( poser.kParmCodeDEPTHMAPSTRENGTH ).SetValue( value )

if you wish to edit each light individually, change the script to the following :


lights = []
for light in scene.Lights():
    lights.append( light.Name() )

lights = chooselights( title, "Please select which lights to edit.", lights )
if lights:
    for light in lights:
        try:
            value = float( gettextentry( title, "Please enter your value ( 0 - 1 )" ) )
        except:
            value = scene.Lights()[light].Value()
        scene.Lights()[light].ParameterByCode( poser.kParmCodeDEPTHMAPSTRENGTH ).SetValue( value )

Locked Out