string $objAligner;if (`window -ex $objAligner`) {
deleteUI -window $objAligner;
}
string $objAligner = `window -t "Object Alignment Tool" -s false -wh 300 100 -ret`;
columnLayout -adj true;
text -l "Instructions: select targets then affected object";
button -l "Execute" -w 300 -h 40 -c "aligner";
showWindow $objAligner;
proc aligner() {
string $prntCnstr = `parentConstraint`;
delete $prntCnstr;
}
import maya.cmds as mcif mc.window(objAligner, ex=True) :
mc.deleteUI(objAligner, window=True)
objAligner = mc.window(title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
mc.columnLayout(adj=True)
mc.text(l='Instructions: select targets then affected object')
mc.button(l='Execute', w=300, h=40, c='aligner()')
mc.showWindow(objAligner)
def aligner() :
prntCnstr = mc.parentConstraint()
mc.delete(prntCnstr)
So what I want to achieve is checking if window I have created is open and if it is then I want to close it and create new one in the same place.
In MEL everything is ok because I can execute the first line of code without anny errors: string $objAligner;
In Python though, we create variable when we assign value to a name so if I open Maya and execute script shown above I get an error of undefined name "objAligner".
Is there any way to solve this?
objAligner = "myWindowName"
if cmds.window(objAligner, exists=True):
cmds.deleteUI(objAligner)
objAligner = mc.window(objAligner, title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
It's just a matter of declaring the variable first.Ok. firstly - I'm new to Python in Maya and my English is not so great either so pardon me that ^^
While I was learning MEL and Python I came across this problem which I can't figure out. So to be more clear I'll show my MEL code first and then it's Python equivalent.
string $objAligner;if (`window -ex $objAligner`) {
deleteUI -window $objAligner;
}
string $objAligner = `window -t "Object Alignment Tool" -s false -wh 300 100 -ret`;
columnLayout -adj true;
text -l "Instructions: select targets then affected object";
button -l "Execute" -w 300 -h 40 -c "aligner";
showWindow $objAligner;
< span style="color: #000;" class="styled-by-prettify">
proc aligner() {
string $prntCnstr = `parentConstraint`;
delete $prntCnstr;
}
So what I want to achieve is checking if window I have created is open and if it is then I want to close it and create new one in the same place. In MEL everything is ok because I can execute the first line of code without anny errors: string $objAligner; In Python though, we create variable when we assign value to a name so if I open Maya and execute script shown above I get an error of undefined name "objAligner". Is there any way to solve this?import maya.cmds as mcif mc.window(objAligner, ex=True) :
mc.deleteUI(objAligner, window=True)
objAligner = mc.window(title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
mc.columnLayout(adj=True)
mc.text(l='Instructions: select targets then affected object')
mc.button(l='Execute', w=300, h=40, c='aligner()')
mc.showWindow(objAligner)
def aligner() :
prntCnstr = mc.parentConstraint()
mc.delete(prntCnstr)
--
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/2a6f3bd4-a4e2-487b-96af-29b6fdae18f7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
objAligner = "myWindowName"
if mc.window(objAligner, exists=True):
mc.deleteUI(objAligner)
objAligner = mc.window(objAligner, title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
Hi Piotr!
Welcome! What I like to do for this is initialize the variable to whatever I want to call the window. It's one of the few UI names I will set explicitly, and you only need to do this for the initial parent object. Like so:
objAligner = "myWindowName" if cmds.window(objAligner, exists=True): cmds.deleteUI(objAligner)It's just a matter of declaring the variable first.objAligner = mc.window(objAligner, title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
Hope that helps!
Joe
On 11/18/2013 5:58 AM, Piotr Makal wrote:
Ok. firstly - I'm new to Python in Maya and my English is not so great either so pardon me that ^^
While I was learning MEL and Python I came across this problem which I can't figure out. So to be more clear I'll show my MEL code first and then it's Python equivalent.
string $objAligner;if (`window -ex $objAligner`) {
deleteUI -window $objAligner;
}
string $objAligner = `window -t "Object Alignment Tool" -s false -wh 300 100 -ret`;
columnLayout -adj true;
text -l "Instructions: select targets then affected object";
button -l "Execute" -w 300 -h 40 -c "aligner";
showWindow $objAligner;
& lt; span style="color: #000;" class="styled-by-prettify">
proc aligner() {
string $prntCnstr = `parentConstraint`;
delete $prntCnstr;
}
So what I want to achieve is checking if window I have created is open and if it is then I want to close it and create new one in the same place. In MEL everything is ok because I can execute the first line of code without anny errors: string $objAligner; In Python though, we create variable when we assign value to a name so if I open Maya and execute script shown above I get an error of undefined name "objAligner". Is there any way to solve this?import maya.cmds as mcif mc.window(objAligner, ex=True) :
mc.deleteUI(objAligner, window=True)
objAligner = mc.window(title='Object Alignment Tool', s=False, wh=(300, 100), ret=True)
mc.columnLayout(adj=True)
mc.text(l='Instructions: select targets then affected object')
mc.button(l='Execute', w=300, h=40, c='aligner()')
mc.showWindow(objAligner)
def aligner() :
prntCnstr = mc.parentConstraint()
mc.delete(prntCnstr)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
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/c28006a6-d1e8-4fb6-affc-831f9f241d9f%40googlegroups.com.