# ignore this line - it's a single line with EOL=LF in order to get the Renderosity forum to display EOL=CR correctly. Bizarre I know !
# AddDeltaAddDelta-01.py
# Use of this script is at your own risk.
# I wrote it for my own use and to the best of my knowledge it works as intended.
# As usual it's been developed using sticky tape, chewing gum and string, plus a few bashes from a hammer.
# The purpose of this script is to allow me to add multiple deltaAddDelta thingies to stuff within Poser.
# I'm uploading it because other people might find it useful. Or need a good laugh.
# Code is identical to my ongoing SimpleERC0-04.py as at 31 Jan 2019 (that was an ongoing version but I got bored - it worked, that was enough for me)
# It's a very cut-down version of Freazypose with most of the unwanted stuff chucked out and extra stuff added for selecting master/slave actors/parameters.
# I wrote it for use with props, not bodypart actors. Can't remember whether it checks and can't be bothered to look.
# This is basically what it does (note that it prints the master/slave actors/parameters to a debug window):
# - 1) Use the current actor as the master (also allows to select a different actor)
# - 2) Select the master parameter from a list of all parameters on the Master Actor (also allows to create a new parameter)
# - 3) Select a slave actor from an expurgated list of actors
# - 4) Select a slave parameter from a list of all parameters on the Slave Actor.Select the deltaAddDelta value.
# - Repeat 3 and 4 as required
# - Add all the deltaAddDelta stuff to the open scene.
# Note that it doesn't save anything, it just adds the master/slave stuff to the open scene in Poser.
# Test the stuff in the scene to make surethat the slaving works as it should, then save whatever you need to, preferably with a new name.
import poser,math
# I've started putting my scripts into classes to avoid possible conflict with stuff in the __main__ module.
# Did they forget to mention that in the PoserPython Manual ?
# Did the folks who wrote the scripts that come with Poser know about that ?
# See my "PoserPython: Global Variables - Question about scope and lifespan" thread at CGBytes for more information, specifically post #7 by bagginsbill:
# http://www.cgbytes.com/community/forums.aspx?g=posts&m=125183#post125183
# Stuff it all in a class, simply to avoid conflict with stuff in the __main__ module.
class cheapskatesTemporaryClass(object):
#
def enterNewParmName(self):
txt = poser.DialogTextEntry(message="Name for new parameter:")
txt.Show()
return txt.Text()
#
def enterDeltaValue(self):
txt = poser.DialogTextEntry(message="Delta value for deltaAddDelta:")
txt.Show()
if float(txt.Text()):
return float(txt.Text())
else:
print "*** Invalid float value"
return 1
# Function to check the Value Operations for the specified parameter and returns the index of the one with the specified valueopname,or -1 if it isn't found
# segidx - just for debugging
# slaveparameter - e.g. act.Parameter(twistdial)
# masterparameter - e.g. curact.Parameter("TwistAll")
# deltavalue
def setValueOp(self,segidx,slaveparameter,masterparameter,deltavalue):
vopidx=-1
idx=0
vops = slaveparameter.ValueOperations()
if vops:
for vop in vops:
if vop.SourceParameter().Name() == masterparameter.Name():
if vopidx !=-1:
print "- *** ALERT: slaveparameter "+slaveparameter.Name()+" has 2+ ValueOps using source parameter "+masterparameter.Name()
vopidx=idx
idx=idx+1
if vopidx == -1:
slaveparameter.AddValueOperation(poser.kValueOpTypeCodeDELTAADD, masterparameter)
slaveparameter.ValueOperations()[-1].SetDelta(deltavalue)
else:
slaveparameter.ValueOperations()[vopidx].SetDelta(deltavalue)
def main(self):
# Get Poser version for doing version-specific stuff
poserversion = '0'
posermainversion = '0'
try:
self.poserversion = poser.AppVersion()
temp = self.poserversion.split('.')
self.posermainversion = temp[0]
except:
pass
ma = 0 # master actor
mp = 0 # master parameter
sa = [] # slave actor(s)
sp = [] # slave parameter(s)
# Abort if using Poser 8/Pp2010 or earlier
# (probably better to use 'hasattr(curact.Parameter("xTran"),"AddValueOperation")' tocheck whether the method exists...
# https://forum.smithmicro.com/topic/3792/poserpython-was-addvalueoperation-added-in-p8-or-p9/4
if int(self.posermainversion) <= 8:
poser.DialogSimple.MessageBox("This script uses the Poser 9/PP2012 PoserPython 'AddValueOperation()' method.\nSince you're using Poser 8/PP2010 or earlier this script won't work.\n\nScript cancelled, no changes made.")
return
# Abort if the user gets cold feet right at the start
confirmed = poser.DialogSimple.YesNo("This script adds deltaAddDelta master/slaving with the current actor as the master.\n\nDo you wish to continue?")
if not confirmed:
confirmed = poser.DialogSimple.YesNo("Do you want to see more information about what this script does?\n\n(This opens a debug window with extra information and terminates the script. You'll probably need to resize the debug window to read the information.)")
if confirmed:
# Briefly explain to the user what this script does and give an option toabort straight away
print "This script adds deltaAddDelta master/slaving with the current actor as the master..."
return
# Abort if no actor selected
scn = poser.Scene()
curact = scn.CurrentActor()
if not curact:
poser.DialogSimple.MessageBox("You need to have an actor selected for this script to do anything.\n\nScript aborted, no changes made.")
return
# Abort if the currently selected actor is childless
#kids = curact.Children()
#if len(kids) == 0:
#poser.DialogSimple.MessageBox("The selected actor must have children for this script to do anything.\n\nScript aborted, no changes made.")
#return
# 1) Let user select the MASTER actor (initially just use current actor)
confirmed = poser.DialogSimple.YesNo("Actor '"+curact.Name()+"' selected as MASTER.\n\nYes to confirm, No to select a different actor")
if confirmed:
ma = curact
print "MASTER Actor = "+ma.Name()
else:
# 1a) Set up a subset list of possible actors to select as master (initially just independent props because I'm doing this for a stack of single-book props)
actlist = poser.Scene().Actors()
subactMenu = []
subactList = []
for act in actlist:
if not act.IsBodyPart() and not act.IsCamera() and not act.IsBase() and not act.IsDeformer() and not act.IsHairProp() and not act.IsZone():
#if act.Parent() == curact:
subactList.append(act)
subactMenu.append(act.Name())
if len(subactList) > 1:
# 1b) Offer a menu and let user select
ma = 0
sel = poser.DialogSimple.AskMenu('Select Master Actor','Select:',subactMenu)
for act in subactList:
if act.Name() == sel:
ma = act
# 3c) Display result
if ma:
print "MASTER Actor = "+ma.Name()
else:
print "FAILED TO SET MASTER ACTOR"
return
# 2) Let user select a parameter in the MASTER actor - this will be the MASTER parameter to which we slave something
poser.DialogSimple.MessageBox("If you wish to create a NEW parameter then select 'None' or 'Cancel' when the menu of parameters is displayed next.")
mplist = ma.Parameters()
mpMenu = []
for p in mplist:
mpMenu.append(p.Name())
sel = poser.DialogSimple.AskMenu('Master Parameter ?','Select:',mpMenu)
for p in mplist:
if p.Name() == sel:
mp = p
if mp:
print "MASTER Parameter = "+mp.Name()
else:
# Ask user for the name of the new parameter
newName = self.enterNewParmName()
if not ma.Parameter(newName):
ma.CreateValueParameter(newName)
else:
poser.DialogSimple.MessageBox("There is already a parameter '"+newName+"' sothat will be used asthe master")
mp = ma.Parameter(newName)
print "MASTER Parameter = "+mp.Name()
# 3) Let user select the SLAVE actor
# 3a) Set up a subset list of possible actors to select as slaves (initially just independent props because I'm doing this for a stack of single-book props)
actlist = poser.Scene().Actors()
subactMenu = []
subactList = []
for act in actlist:
if not act.IsBodyPart() and not act.IsCamera() and not act.IsBase() and not act.IsDeformer() and not act.IsHairProp() and not act.IsZone():
#if act.Parent() == curact:
subactList.append(act)
subactMenu.append(act.Name())
if len(subactList) > 1:
poser.DialogSimple.MessageBox("After adding the first slave you'll be able to add more slaves.\nWhen you've finished select 'None' or 'Cancel' fromthe Slave Actor selection")
slaveList = [] # [0][0] = Slave Actor 1, [0][1]= Slave Parameter 1, [0][2] = Delta 1, [1][0] = Slave Actor 2, [1][1]= Slave Parameter 2, [1][2] = Delta 1, etc
while True:
# 3b) Offer a menu and let user select
sa = 0
sel = poser.DialogSimple.AskMenu('Select Slave Actor','Select:',subactMenu)
for act in subactList:
if act.Name() == sel:
sa = act
# 3c) Display result
if sa:
print "SLAVE Actor = "+sa.Name()
else:
break # Selecting 'None'or 'Cancel'from Slave Actor selection indicates that all required slaves have been selected
# 4)Let user select a parameter in the SLAVE actor
# 4a) Set up a menu, display it, and get user's selection
splist = sa.Parameters()
spMenu = []
for sp in splist:
spMenu.append(sp.Name())
sel = poser.DialogSimple.AskMenu('Select Slave Parameter','Select:',spMenu)
for p in splist:
if p.Name() == sel:
sp = p
# 4b) Display result
if mp:
print "SLAVE Parameter = "+sp.Name()
else:
print "FAILED TO SET SLAVE PARAMETER"
return
# 5) Let the user select the delta value forthe slaving
# Ask user for the name of the new parameter
delta = self.enterDeltaValue()
print "DELTA Value = "+str(delta)
# append the data to our list
newSlave = []
newSlave.append(sa)
newSlave.append(sp)
newSlave.append(delta)
slaveList.append(newSlave)
# Slave the slave-parameter(on the slave-actor) to the master-parameter (on the master-actor)
print "About to set up the deltaAddDeltas..."
for slave in slaveList:
print " - slaving "+slave[0].Name()+" actor's "+slave[1].Name()+" parameter with a delta value of "+str(slave[2])
self.setValueOp(0,slave[1],mp,slave[2])
print "...done"
else:
poser.DialogSimple.MessageBox("Can't find any possible actors to be the slave.\n\nScript aborted, no changes made.")
return
# Inform the user that it's all done
poser.DialogSimple.MessageBox("Script completed successfully...")
poser.DialogSimple.MessageBox("Running 3DCheapskates AddDeltaAddDelta-01.py script\n\n(N.B. You should see a similar message when the script finishes. If you don't then the script has crashed!)")
cheapskatesTemporaryInstance = cheapskatesTemporaryClass()
cheapskatesTemporaryInstance.main()
poser.DialogSimple.MessageBox("3DCheapskates AddDeltaAddDelta-01.py script all done without crashing !")