semiprowolverine
July 6th, 2012, 12:08 PM
After going through every possible resources I came to conclusion that I need someone to enlighten me on passing global variables from a function to others inside a Module in Python.
Actually I am writing a small UI in Autodesk Maya2010, here is a brief about the problem.
In the following code, I have got two Module Level Global Variables. I am assigning values to them inside a function. Now if I pass these variables directly(i.e. without converting the function call and assigning it as a string) then the code works fine, however since the Command Flag of the Button Function only allows a string or a function name hence I am stuck with this way of calling the function.
The weird thing about this is when I pass only one argument then it gets read in the called function, however with two or more arguments it is using only Module Level Global variables.
The result which I get is :
temp_var=None
a_Window=None
which I have got no idea about.
Can anyone point me in the right direction about how to deal with this issue and can someone tell me what exactly is happening when I use the string value as function call?
Here is the Sample Code:
import maya.cmds;
temp_var=None;
a_Window=None;
def im_PrimaryFunc():
imSecondary_func();
def imSecondary_func():
global a_Window;
global temp_var;
a_Window=maya.cmds.window(title="Something");
a_layout=maya.cmds.columnLayout(adj=1,rs=10);
temp_var=maya.cmds.createNode("polySphere");
func_call="a_calledFunc(a_Window,temp_var)";
maya.cmds.button(label="call_aFunc",align="center",command=func_call);
maya.cmds.showWindow(a_Window);
def a_calledFunc(arg00,arg01):
print(arg00);
print(arg01);
im_PrimaryFunc();
Thanks,
Actually I am writing a small UI in Autodesk Maya2010, here is a brief about the problem.
In the following code, I have got two Module Level Global Variables. I am assigning values to them inside a function. Now if I pass these variables directly(i.e. without converting the function call and assigning it as a string) then the code works fine, however since the Command Flag of the Button Function only allows a string or a function name hence I am stuck with this way of calling the function.
The weird thing about this is when I pass only one argument then it gets read in the called function, however with two or more arguments it is using only Module Level Global variables.
The result which I get is :
temp_var=None
a_Window=None
which I have got no idea about.
Can anyone point me in the right direction about how to deal with this issue and can someone tell me what exactly is happening when I use the string value as function call?
Here is the Sample Code:
import maya.cmds;
temp_var=None;
a_Window=None;
def im_PrimaryFunc():
imSecondary_func();
def imSecondary_func():
global a_Window;
global temp_var;
a_Window=maya.cmds.window(title="Something");
a_layout=maya.cmds.columnLayout(adj=1,rs=10);
temp_var=maya.cmds.createNode("polySphere");
func_call="a_calledFunc(a_Window,temp_var)";
maya.cmds.button(label="call_aFunc",align="center",command=func_call);
maya.cmds.showWindow(a_Window);
def a_calledFunc(arg00,arg01):
print(arg00);
print(arg01);
im_PrimaryFunc();
Thanks,