Hi Gabriele:

You might want to look at some sample code for creating windows. (e.g. http://stackoverflow.com/questions/3492106/creating-a-maya-ui)

However, more to the point, the reason you cannot access toggle_test is because it is out of scope, and only launchUI() knows about it. If you want printIt to have access to toggle_test, I would place these two methods in a class and have that variable be a instance variable.

On 7/16/2014 8:49 AM, Gabriele Bartoli wrote:
Following everybody's hints, I got to this point:

|
# Load maya commands module
importmaya.cmds asmc

# Build the UI
deflaunch_UI():

# This prevents multiple windows to pop up
ifmc.window("myWindow",ex=True):
        mc.deleteUI("myWindow",window=True)

# Window set-up
    mc.window("myWindow",title="Test Window",s=False,wh=(300,100))
    mc.columnLayout(adj=True)
    toggle_test =mc.checkBox(label ='Toggle me!',value =False)
mc.button(l="Press to print the value of the checkbox below",w=300,h=100,
              command =printIt)
    mc.showWindow("myWindow")

# Print the value
defprintIt():

# Query toggle status
var=mc.checkBox(toggle_test,query =True,value =True)

# Print the status
print"Checkbox's status is:",var

launch_UI()
|

And the shelf button still looks like this:

|
importtestScript
reload (testScript)
|

I'm sticking with having the UI launched from within the script simply because it allows me to run the code from both the script editor and the shelf. I seem to understand it shouldn't be like that, so I'll fix it when the debugging is done :)

When I run it, the UI pops up and at button press I get this error:

|
# Error: printIt() takes no arguments (1 given)
# TypeError: printIt() takes no arguments (1 given) #
|

So I edited the printIt function like this:

|
# Print the value
defprintIt(test):

printtest

# Query toggle status
var=mc.checkBox(toggle_test,query =True,value =True)

# Print the status
print"Checkbox's status is:",var
|

I get a printout of test as "False", but I am at a loss to what that value refers to and from where it comes from.

Plus, I get a new error :P

|
# Error: NameError: file D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 25: global name 'toggle_test' is not defined #
|

I was thinking of feeding "toggle_test" to print it using the call back, like this:

|
mc.button(l="Press to print the value of the checkbox below",w=300,h=100,command=printIt(toggle_test))
|

This doesn't seem to work though. This is what I get:

|
# Error: TypeError: file D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 16: Invalid arguments for flag 'command'. Expected string or function, got NoneType #
|

I guess I could simply define it as a global variable and be done with it, but I don't think is the best option. Unless it is the ONLY option, which would make it the best option too >P

Thanks a lot guys, and I apologize if I am being a N00b

Cheers
--
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] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3075c5c8-5215-461f-86d3-39adde494131%40googlegroups.com <https://groups.google.com/d/msgid/python_inside_maya/3075c5c8-5215-461f-86d3-39adde494131%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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/53C6A36F.5050309%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to