Hey guys! I
have started to write my very first script in Python for Maya and it seems to
work just fine but I want to improve it in a few ways.
So first I'm going to show and describe this script for you and then those
things I want to change/add.
How it looks:
http://i.imgur.com/tRLRX7Y.png
Code:
http://pastebin.ubuntu.com/6478436/
What it does:
Main purpose of this tool/script is to be an alternative and more convenient
way to set up "Custom axis orientation" which in Maya is represented in
radians. So what actually this tool allows you to do is to set X, Y and Z
orientation in degrees. Furthermore it gives you some additional options (as
you can see in the screenshot above).
How I want to improve it:
1. Allow to set Custom axis orientation for Rotation tool.
This is probably the hardest thing (I assume). As you can see in the image
above, "Rotation" option is currently greyed out. That’s because
manipRotateContext doesn’t have "Custom axis orientation" mode (http://download.autodesk.com/global/docs/maya2013/en_us/CommandsPython/show.html?manipRotateContext.html&cat=General).
Is there a way to achieve this effect - rotate Rotation axis?
2. Refresh text (values) in frame "Current values in degrees" after clicking on "Apply" button.
When window is created, in frame "Current values in degrees" values of X, Y and
Z are retrieved from three fields in "Custom axis orientation". Then they are converted to degrees and displayed
(lines 63-83 in the code linked above). But what I also want is to refresh them
each time I click "Apply" button. Is there a way to achieve this?
3. Combine formatting of "width", "align" and
"precision" in Python.
Lines 75-83 are showing Python .format method. Each value has 3 float digit
precision (.3f) and in addition to that they are right-aligned with 10 value
(>10). Ok, that’s good but I what also want is to have three "0" before dot. So I
want apply [width] to it (http://docs.python.org/2.6/library/string.html#format-specification-mini-language).
But I don’t know how to mix [align], [width] and [.precision] together in one formatting
{}.
4. Code
improvements
Because it’s my first script/tool and because I have learning Python for only 3
month now – I don’t have too much experience in it – any advice about the code
structure will be highly appreciated :*
PS. And as always sorry for my English.
2. Refresh text (values) in frame "Current values in degrees" after clicking on "Apply" button.
When window is created, in frame "Current values in degrees" values of X, Y and Z are retrieved from three fields in "Custom axis orientation". Then they are converted to degrees and displayed (lines 63-83 in the code linked above). But what I also want is to refresh them each time I click "Apply" button. Is there a way to achieve this?
self.curMoveDegVal = []
...applyButton = cmds.button(l='Apply',height=26,c=self.degToRad)...def updateText():# update the current degree text with# self.curMoveDegVal# self.curScaleValdef clickCmd(self, *args):self.degToRad()self.updateText()def degToRad(self):xDeg = self.xDegyDeg = self.yDegzDeg = self.zDegrelativeOpt = self.relativeOptapplyFor = self.applyFor
3. Combine formatting of "width", "align" and "precision" in Python.
Lines 75-83 are showing Python .format method. Each value has 3 float digit precision (.3f) and in addition to that they are right-aligned with 10 value (>10). Ok, that’s good but I what also want is to have three "0" before dot. So I want apply [width] to it (http://docs.python.org/2.6/library/string.html#format-specification-mini-language). But I don’t know how to mix [align], [width] and [.precision] together in one formatting {}.
4. Code improvements
Because it’s my first script/tool and because I have learning Python for only 3 month now – I don’t have too much experience in it – any advice about the code structure will be highly appreciated :*
PS. And as always sorry for my English.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f002cc5e-5a10-4c24-b06b-a71c53860f90%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Correction on the first part... you are currently using a closure to pass the references of your widgets to your degree callback. It would end up being easier to switch to a class with instance attributes so that you can also reference your lists of values.
class MyWindow(object) :
def __init__(self) :
self.curMoveVal = cmds.manipMoveContext('Move', query=True, orientAxes=True)
def updateText(self, *args) :
return self.curMoveVal
def caoidWin(self) :
testWindow = 'someName'
if cmds.window(testWindow, ex=True) :
cmds.deleteUI(testWindow, window=True)
testWindow = cmds.window(
testWindow,
title='testWindow',
wh=(400,200))
cmds.columnLayout(
adjustableColumn=True,
rowSpacing=10)
cmds.text(
l='{0}'.format(self.updateText()))
cmds.button(
l='Apply',
c=self.updateText)
cmds.showWindow(testWindow)
a = MyWindow()
a.caoidWin()
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
class MyWindow(object):def __init__(self):self.testWindow = 'someName'
self.curMoveVal = cmds.manipMoveContext('Move', query=True, orientAxes=True)def updateText(self, *args) :
cmds.text(self.text, e=True, l=str(self.curMoveVal))def caoidWin(self) :testWindow = self.testWindow
if cmds.window(testWindow, ex=True) :cmds.deleteUI(testWindow, window=True)
self.testWindow = cmds.window(
testWindow,title='testWindow',wh=(400,200))cmds.columnLayout(adjustableColumn=True,rowSpacing=10)
self.text = cmds.text(l=str(self.curMoveVal))
cmds.button(l='Apply',c=self.updateText)
cmds.showWindow(self.testWindow)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4c4f7dd6-aefd-453c-a75d-7b1185f57baf%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
OMG! Thank you Justin, it works! Now I'm going to take some time to analyze what you write in your code example and try to make it work in my proper script. But once again - thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f002cc5e-5a10-4c24-b06b-a71c53860f90%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.