pitklad opened this issue on Nov 30, 2012 · 5 posts
pitklad posted Fri, 30 November 2012 at 4:27 AM
I want to randomize various props as if those were thrown on air
don't want to move them around just randomize their rotation values
Is there a python script like that?
PhilC posted Fri, 30 November 2012 at 8:05 AM
import poser
import random
scene = poser.Scene()
def main():
for actor in scene.Actors():
# ues try/except to avoid trying to rotating actors that can not.
try:
if actor.IsProp():
print actor.Name()
actor.ParameterByCode(poser.kParmCodeXROT).SetValue(rnd())
actor.ParameterByCode(poser.kParmCodeYROT).SetValue(rnd())
actor.ParameterByCode(poser.kParmCodeZROT).SetValue(rnd())
except:
pass
def rnd():
value = random.uniform(-360,360)
print "t%f" % value
return value
main()
scene.DrawAll()
print "done"
pitklad posted Fri, 30 November 2012 at 6:24 PM
You are the best!
It works great!
Is it possible to make it work on the selected prop only? In case there are other props on the scene?
markschum posted Fri, 30 November 2012 at 6:47 PM
the line "for actor in scene.Actors():" is going to go through every prop, light, camera etxc in the scene.
def main():<br></br><br></br> actor = scene.CurrentActor()<br></br><br></br> # ues try/except to avoid trying to rotating actors that can not.<br></br><br></br> try:<br></br><br></br> if actor.IsProp():<br></br><br></br> print actor.Name()<br></br><br></br> actor.ParameterByCode(poser.kParmCodeXROT).SetValue(rnd())<br></br><br></br> actor.ParameterByCode(poser.kParmCodeYROT).SetValue(rnd())<br></br><br></br> actor.ParameterByCode(poser.kParmCodeZROT).SetValue(rnd())<br></br><br></br> except:<br></br><br></br> pass<br></br><br></br>make the change and get the indentations right and it will do only the selected actor (prop)<br></br><br></br><br></br>
pitklad posted Fri, 30 November 2012 at 7:13 PM
Perfection! Thank you markschum!
Python seams like magic to me, I assumed the spell should be changed a little to work :biggrin: