Forum: Poser Python Scripting


Subject: Can Python Change the Dials into Digital Displays?

CyberStretch opened this issue on Aug 31, 2002 ยท 12 posts


ockham posted Sun, 01 September 2002 at 11:15 AM

I should add that the number on the Scale can be formatted to any degree of fineness as well. So if you want the slider to show the difference between 0.000003 and 0.000004, you can. Also, you mentioned examples. Here's the code that produces the image above. I'm trying out Bushi's new notational convention here. The bottom part of the code is sort of pointless; I was attempting to rig up a way around the Gimbal Lock problem which didn't work, but at least you can see something happen in response to the sliders. #--------------------------- from Tkinter import * import poser import math RadToDeg = 180.0 / math.pi DegToRad = math.pi / 180.0 startText = "" #----------------------------------------- # Visible part: using Scale sliders. #------------------------ class App: ~def init(self, master, textMessage): ~self.Go = 0 ~self.master = master ~self.deltaX = 0.0 ~self.deltaY = 0.0 ~self.deltaZ = 0.0 ~Label(master, text="x:").grid(row=1, sticky=W) ~Label(master, text="y:").grid(row=2, sticky=W) ~Label(master, text="z:").grid(row=3, sticky=W) ~self.XEntry = Scale(master, from_= -90.0, to=90.0,orient=HORIZONTAL,resolution=1.0) ~self.XEntry.grid(row=1, column=2) ~self.YEntry = Scale(master, from_= -90.0, to=90.0,orient=HORIZONTAL,resolution=1.0) ~self.YEntry.grid(row=2, column=2) ~self.ZEntry = Scale(master, from_= -90.0, to=90.0,orient=HORIZONTAL,resolution=1.0) ~self.ZEntry.grid(row=3, column=2) ~scene = poser.Scene() ~try: ~~self.ca = scene.CurrentActor() ~except: ~~raise("No object selected") ~if not self.ca.IsProp(): ~~raise("Not a prop!") ~self.xParm = self.ca.Parameter("xRotate") ~self.origX = self.xParm.Value() ~self.yParm = self.ca.Parameter("yRotate") ~self.origY = self.yParm.Value() ~self.zParm = self.ca.Parameter("zRotate") ~self.origZ = self.zParm.Value() # Put existing values into the sliders ~self.XEntry.set(self.origX) ~self.YEntry.set(self.origY) ~self.ZEntry.set(self.origZ) # buttons for Go, cancel. ~self.buttonGo= Button(master, text="Go", command=self.handleGo) ~self.buttonGo.grid(row=4, column=1) ~self.buttonGo= Button(master, text="No", command=self.handleCancel) ~self.buttonGo.grid(row=4, column=2) # - - - - - - - - - - - - - - - - - - # Real action happens outside the TK loop, using these vars. #---------------------- ~def handleGo(self): ~~self.Go = 1 ~~try: ~~~self.enteredX = float(self.XEntry.get()) ~~except: ~~~self.enteredX = 0.0 ~~try: ~~~self.enteredY = float(self.YEntry.get()) ~~except: ~~~self.enteredY = 0.0 ~~try: ~~~self.enteredZ = float(self.ZEntry.get()) ~~except: ~~~self.enteredZ = 0.0 ~~self.master.quit() #--------------------- ~def handleCancel(self): ~~self.Go = 0 ~~self.master.quit() #---------------------- # Activate the Win loop, which will be broken by any button. #----------------------- root = Tk() app = App(root, startText) root.mainloop() #---------------------- # End TK loop. #---------------------- if (app.Go): ~# Figure the new angles. ~# Y stays as is. ~# As Y goes to 90, the entered X must affect Z more and X less, ~# which means that the resultant Z takes enteredX * sin Y, ~# and the resultant X takes enteredX * cos Y. ~# As Y goes to 90, the entered Z must affect X more and Z less, ~# which means that the resultant Z takes enteredZ * cos Y, ~# and the resultant X takes enteredZ * sin Y. ~radY = app.enteredY * DegToRad ~resultZ = (app.enteredX * math.sin(radY)) + (app.enteredZ * math.cos(radY)) ~resultX = (app.enteredX * math.cos(radY)) + (app.enteredZ * math.sin(radY)) # Insert the new rots: ~app.xParm.SetValue(resultX) ~app.yParm.SetValue(app.enteredY) ~app.zParm.SetValue(resultZ) ~app.ca.MarkGeomChanged()

My python page
My ShareCG freebies