Sat, Nov 30, 1:51 AM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Need help with this script: have I nested loops?


Tguyus ( ) posted Tue, 06 May 2008 at 11:02 PM · edited Sat, 30 November 2024 at 1:19 AM

Ok, by way of disclaimer, I really know nothing about Python (though I'd love to learn).  After studying a bunch of scripts, and doing some trial and error, I managed to adapt the copyparms.py script included in the P7 utility group so it would scale morph targets applied to the hip, buttock, and thigh based on the value for the thigh's Bend parameter.  It works, but it's really slow.  My best guess is that I've somehow nested some loop routines so it's going through all the animation frames a gazillion times. 

If one of the python gurus here would be kind enough to take a quick look and suggest how I could fix it, I'd REALLY appreciate it!

tguyus

p.s.   I think I'm supposed to attach scripts as text files here but I'm not sure how to do that.  Also, I think (hope) it's short enough that people won't be upset if I paste in the whole thing.

#-----------------------------------------------------------------------------

This script will scale the 59Thi100R and 59Thi100L morph target values based on

#  bend parameter values for the right and left thighs repsectively of the V59 Akina figure. 
#  Needs to be refined to scale same MTs for currently selected figure.

Thigh Bend MT Scaler

April 27, 2008

Tguyus

Adapted from copyparms.py script in P7 utility scripts

#-----------------------------------------------------------------------------

These are the parm names to copy from thighs of V59 Akina to target MTs of same figure

#-----------------------------------------------------------------------------
srcParm1 = ["Bend"]
copyParms1 = ["59Thi100R"]
copyParms2 = ["59Thi100L"]

import poser
scene = poser.Scene()

#-----------------------------------------------------------------------------

Find the figure

#-----------------------------------------------------------------------------

figureFrom = scene.Figure("V59 Akina")
figureTo = scene.Figure("V59 Akina")

#-----------------------------------------------------------------------------

Find the parameter(s)

#-----------------------------------------------------------------------------

rightthighFrom = figureFrom.Actor("rThigh")
rightthighTo = figureTo.Actor("rThigh")
leftthighFrom = figureFrom.Actor("lThigh")
leftthighTo = figureTo.Actor("lThigh")
rightbuttockTo = figureTo.Actor("rButtock")
leftbuttockTo = figureTo.Actor("lButtock")
righthipTo = figureTo.Actor("hip")
lefthipTo = figureTo.Actor("hip")

#-----------------------------------------------------------------------------

Remember when we started from:

#-----------------------------------------------------------------------------
rememberFrame = scene.Frame()

#-----------------------------------------------------------------------------

Blank all the keyframes in the destination...(the easy way, on every frame)

#-----------------------------------------------------------------------------
for parmName in copyParms1:
.....parmTo1 = rightthighTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo1.DeleteKeyFrame(frame)
.....parmTo2 = rightbuttockTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo2.DeleteKeyFrame(frame)
.....parmTo3 = righthipTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo3.DeleteKeyFrame(frame)

for parmName in copyParms2:
.....parmTo4 = leftthighTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo4.DeleteKeyFrame(frame)
.....parmTo5 = leftbuttockTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo5.DeleteKeyFrame(frame)
.....parmTo6 = lefthipTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
..........parmTo6.DeleteKeyFrame(frame)

#-----------------------------------------------------------------------------

Copy all keyframes the parms..(the hard way, go to each successive key

#-----------------------------------------------------------------------------
for parmName in copyParms1:
..... parmTo1 = rightthighTo.Parameter(parmName)
..... parmTo2 = rightbuttockTo.Parameter(parmName)
..... parmTo3 = righthipTo.Parameter(parmName)
.....for frame in range(scene.NumFrames()):
.........scene.SetFrame(0)
.........while 1:
.......... parmTo1.SetValue(rightthighFrom.Parameter("Bend").Value() * -0.01)
.......... parmTo2.SetValue(rightthighFrom.Parameter("Bend").Value() * -0.01)
.......... parmTo3.SetValue(rightthighFrom.Parameter("Bend").Value() * -0.01)
.......... nextKey = parmFrom.NextKeyFrame()
.......... if (nextKey == None):
............... break
.......... scene.SetFrame(nextKey)

for parmName in copyParms2:
..... parmTo4 = leftthighTo.Parameter(parmName)
..... parmTo5 = leftbuttockTo.Parameter(parmName)
..... parmTo6 = lefthipTo.Parameter(parmName)
..... for frame in range(scene.NumFrames()):
.........scene.SetFrame(0)
.........while 1:
.......... parmTo4.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
.......... parmTo5.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
.......... parmTo6.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
.......... nextKey = parmFrom.NextKeyFrame()
.......... if (nextKey == None):
............... break
.......... scene.SetFrame(nextKey)

#-----------------------------------------------------------------------------

Return to when we started from:

#-----------------------------------------------------------------------------
scene.SetFrame(rememberFrame)

#-----------------------------------------------------------------------------

Script completion notification:

dlg = poser.Dialog(file="./Runtime/ui/simpleDlgOk.xml", title="Script Completion",
...............message="The script has completed its run.n"
.........................+"Click OK to move onn", width=500, height=170)
proceed = dlg.Show()

if (not proceed):
.....raise "Aborting"


markschum ( ) posted Wed, 07 May 2008 at 2:04 PM

for frame in range(scene.NumFrames()):
.........scene.SetFrame(0)
.........while 1:

I dont follow this bit , you seem to be looping through the frames with the while statement , and breaking out of it rather than arranging a clean end of the while , but then what is the frame in range loop doing ?

You seem to have only 1 name in copyparms 1 and 2 but thats ok, allows for expansion .

you can do stuff like
leftthighTo.Parameter(parmName).SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
if you want .

getting the paramater allows you to test its existance before trying to set its value , but you arent doing that .


ockham ( ) posted Fri, 09 May 2008 at 1:51 AM · edited Fri, 09 May 2008 at 1:52 AM

Markschum has caught the problem.

If you're only going to set the value at keyframes, you don't need the
outer loop on range(scene.NumFrames()).  The while loop based
on NextKeyFrame will do the whole job.

This would do well enough in each case:

for parmName in copyParms2:
..... parmTo4 = leftthighTo.Parameter(parmName)
..... parmTo5 = leftbuttockTo.Parameter(parmName)
..... parmTo6 = lefthipTo.Parameter(parmName)
......scene.SetFrame(0)
......while 1:
....... parmTo4.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo5.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo6.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... nextKey = parmFrom.NextKeyFrame()
....... if (nextKey == None):
............ break
....... scene.SetFrame(nextKey)

My python page
My ShareCG freebies


Tguyus ( ) posted Sat, 10 May 2008 at 2:11 PM

Quote - Markschum has caught the problem.

If you're only going to set the value at keyframes, you don't need the
outer loop on range(scene.NumFrames()).  The while loop based
on NextKeyFrame will do the whole job.

This would do well enough in each case:

for parmName in copyParms2:
..... parmTo4 = leftthighTo.Parameter(parmName)
..... parmTo5 = leftbuttockTo.Parameter(parmName)
..... parmTo6 = lefthipTo.Parameter(parmName)
......scene.SetFrame(0)
......while 1:
....... parmTo4.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo5.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo6.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... nextKey = parmFrom.NextKeyFrame()
....... if (nextKey == None):
............ break
....... scene.SetFrame(nextKey)

Sorry for the delayed expression of thanks, but I just got back from a road trip.  So... THANKS!  I'll try this improved code!  cheers...


Tguyus ( ) posted Sun, 11 May 2008 at 4:13 PM

Quote - Markschum has caught the problem.

If you're only going to set the value at keyframes, you don't need the
outer loop on range(scene.NumFrames()).  The while loop based
on NextKeyFrame will do the whole job.

This would do well enough in each case:

for parmName in copyParms2:
..... parmTo4 = leftthighTo.Parameter(parmName)
..... parmTo5 = leftbuttockTo.Parameter(parmName)
..... parmTo6 = lefthipTo.Parameter(parmName)
......scene.SetFrame(0)
......while 1:
....... parmTo4.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo5.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... parmTo6.SetValue(leftthighFrom.Parameter("Bend").Value() * -0.01)
....... nextKey = parmFrom.NextKeyFrame()
....... if (nextKey == None):
............ break
....... scene.SetFrame(nextKey)

hmmm... doesn't work, alas.

First fix attempt = deleted the "for frame in range(scene.NumFrames()):" line only.  This made it match the code pasted above in the quote, with periods = spaces.  Led to syntax error on "scene.SetFrame(0)" line.  

Second fix attempt = various experiments revising indentations.  Led to errors of either syntax for lines in the looping routine (e.g., the "while 1:" line) or undefined parameter error for "parmFrom".

So... not sure what to try next.  If anyone has suggestions, I'd really appreciate it!  And thanks again for your help so far.

cheers...


Tguyus ( ) posted Mon, 12 May 2008 at 10:10 AM

Okay, I got it.  I actually kept the "for frame in range..." loop and changed the "nextkey" line to "nextkey = rightthighFrom.NextKeyFrame()" in the copyparms1 loop (and same using "leftthighFrom" for copyParms2 loop).  Now it blazes through its routine, changing the relevant morph targets everywhere there is a change in each thigh bend parameter. 

It's also nice that I don't have to pick each thigh in turn.  It runs even if I have BODY selected.  If I tinker with it further, it'll be to try to make the script more generic so I can just run it on whatever figure I have selected rather than having to have 3 different versions for the 3 characters I use it on.  But to do that, I'll have to read up on how to code it so it uses the currently selected figure. 

Anyway, sincere thanks once again to markschum and ockham for taking a look at it!

cheers...


markschum ( ) posted Mon, 12 May 2008 at 11:25 AM

no problem

fig =  poser.Scene().CurrentFigure()    gets you the current figure


Tguyus ( ) posted Wed, 14 May 2008 at 2:43 PM

Quote - no problem

fig =  poser.Scene().CurrentFigure()    gets you the current figure

Cool!  Thanks markschum.  I'll give that a try.  cheers...


Privacy Notice

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.