When I try this it returns an error: CODE # Error: Invalid arguments for flag 'command'. Expected string or function, got NoneType # Traceback (most recent call last): # File "", line 2, in ? # File "", line 262, in UI # TypeError: Invalid arguments for flag 'command'. Expected string or function, got NoneType #
is it at all possible to pass parameters to a function through the button mel command?
Yes but only globals have any meaning for the ELF items, because they are not being called form your script but outside form it. And your scipt has long since terminated its run wehan the button is being pressed (otherwise it would block the gui)
Its far better to chek everything at once every time a action and pack the name of some widget permanently into teh command program then you wouldn't need the global variable.
(besides doing it his way each time a item is changed to change some internal value that then gets passed to the execute is strictly speaking double bookkeeping, as long as the gui exists every piece of info is already being stored in it)
Thanks for the reply! Sorry for the late respond time, I have been quite busy.
What if for example you want this setup:
import maya.cmds as cmds
class myTool:
a = myTool() a.myBrowser()
The only way I can make the filebrowserdialog work is when I declare the command and the procedure globally wich I dont want... I want the fileBrowserDialog and the file command to be within my class.
any suggestions how to fix this? thanx in advance, Sjoerd
Yes but you must leave something global there for you to call into. In this case i would make the object "a" global with some non clash able name. By the way if you execute that inside mayas console as is you just have made a and also mytool definitions global.
You cannot make the functions totally local or the succession would become this:
your script runs its class definitions your scripts make a class isntance you create a gui your instance dies your instance gets cleaned away your class gets cleaned away A aeon in computer time passes User presses button nothing happens
So you must leave some handle back to the originator, this is a very common gui programming problem events also allmost allways need to be bound to some globals that have some so scope they dont die before they get triggered. It does not just apply to maya it applies to quite many other stuffs too such as hooking into windows messages without a pump loop.
It would be different if the gui was a main loop you made but it inst its running inside mayas main loop. You arent, and you wont be in any case ever. But you cant lock into a loop because mayas then just running your code and never returning. Well technically speaking you could loop out in thread but thats just stupid, you could as easily kill the global variable later.
QUOTE wich I dont want... I want the fileBrowserDialog and the file command to be within my class.
global or not they are within your class. The proc definition does not need to be global it will live as long as the object a is alive.
PS this is the reason python implements namespace.
PPS. also incidentally even if your using python you cant escape how maya works, its still mel even tough you write it oin python.
CODE # Error: line 1: Cannot find procedure "importImage". #
This script is actually taken from the maya help. So it should work but it doesn't. So I think this command still doesn't work to well in Maya Python...
QUOTE This script is actually taken from the maya help. So it should work but it doesn't. So I think this command still doesn't work to well in Maya Python...
Yes but how do you execute it?
globality and locality is very important stuff to understand. otherwise it will never work out for you.
Anyway your most likely actually calling for the mel verion of import image here sho you should wrap that up into a python command call. ill look into it but i have a deadline to friday so...
PS. you don't happen to use a a external python interpreter by any chance?
Which returns an error: # Error: "C:/Documents and Settings/maya/Desktop/bpw_test1.0275.iff" "image"; # # Error: Line 1.1: Syntax error #
The command calls to the python procedure like this: importImage "C:/Documents and Settings/maya/Desktop/bpw_test1.0275.iff" "image" which is cool in MEL, but in python should be like this: importImage("C:/Documents and Settings/maya/Desktop/bpw_test1.0275.iff", "image")
the last one works when I execute it manually in the editor. Do you think there is a way past this syntax problem?
Some of the callbacks in Maya have been switched over to accept python or mel code and some have not.
If in a mel tab, you enter [codebox]help fileBrowserDialog;[/codebox] you'll get the quick help for the command, which lists all the flags and their associated types. Notice the -fc flag line which is giving you trouble.
-fc -fileCommand String
It's associated type is String, if it were Script then your code would work as expected. The workaround is simple. It's expecting a mel command string, give it one. In the form 'python("myFunction")'.
it does execute the file browser right, but that was never the question. It just never executed the callback right it did execute the python statement but even thet wasnt the question at hand. See its not just a procedure mayas also trying to execute its contents by passing parameters in and that is what we cant do.
see some few maya command dont just execure functions they requitre fuctions that get passed input values and thats not what we are able to do. Still leaves out the values for the function.
And yes it runs without erroring but that don't mean it does things right.
right now maya executes
python("importImage") "....path to selected file../filename" "image";
wich is obviously not the intent nor the result this thread is looking for. Your comment is right but its the wrong kind of callback your thinking of. theres just no way to get the parameters passed in at least not with that method
the synax is what i showed you, but python must have , between arguments and ) at last maya dont inject this so theres really no other way around. Or a more generic wrapper one