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)
|
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.
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;
proc aligner(){
string$prntCnstr =`parentConstraint`;
delete$prntCnstr;
}
|
|
importmaya.cmds asmc
ifmc.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)
defaligner():
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?
--
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 [email protected].
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.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/528A3DCA.1040406%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.