PDA

View Full Version : Defining a procedure in userSetup.mel


AdamMax
11-15-2010, 04:02 AM
Hi guys,
I'm trying to launch maya from the command line (via python) and have it run a procedure that I've put in userSetup.mel. The procedure is given the location of a txt file "mayafileList" so that it can do stuff with the contents of the text file.

So firstly.
I've put "userSetup.mel" in
C:\Documents and Settings\Me\My Documents\maya\2011\scripts\userSetup.mel
Is this the correct location for getting a mel script to run on startup? It appears to be running it because I'm getting syntax errors on my code (below).

This is the code for userSetup.mel


proc Batch_Export (mayafileList, overw){ $f = 'fopen mayafileList "r"';
while (!'feof $f'){
string $source_url = 'fgetline $f';
string $dest_url = 'fgetline $f';
file -o $source_url;
file -force -options "" -type "FileType" -pr -ea $dest_url' -prompt;
}
fclose $f;
}



I'm getting syntax errors for my procedure. Not the most helpful error either (no line number or description).

And the command line executed from a python script using os.system() so that I can pass it arguments is;

maya -command 'Batch_Export(mayafileList, overw);' -prompt


Any help would be appreciated,
I cant seem to fix the errors I get on Maya load

// Error: proc Batch_Export (mayafileList, overw){ //
// Error: Syntax error //
// Error: proc Batch_Export (mayafileList, overw){
//
// Error: Syntax error //
// Error: $f = 'fopen mayafileList "r"';
//
// Error: Syntax error //
// Error: while (!'feof $f'){
//
// Error: Syntax error //
// Error: string $dest_url = 'fgetline $f';
//
// Error: Syntax error //
etc

Mark-J
11-15-2010, 07:45 AM
Your main syntax error is in the main declaration,
proc Batch_Export (mayafileList,overw)
remember this is mel, so you need to declare what these variable types are being passed, ie:
string $mayafileList,
It's a pain if you've been in Python having to remember the mel syntax :)

AdamMax
11-15-2010, 10:52 AM
Thanks Mark.
I'll try that out tomorrow. I'm completely new to mel, after coming from maxscript and python I'm finding the mel documentation rather... sparse.

sp0rk3d
11-15-2010, 08:10 PM
i may be mistaken but can't you also make a usersetup.py file? and write your code in python if that is better for you...

AdamMax
11-16-2010, 05:18 AM
Thanks for the help guys, I'm nearly there
Moving onto the next problem :)

I have the procedure defined on startup via userSetup.mel. The procedure basically loads the given file (an arg in the procedure) and exports it with a custom exporter type.

I start Maya from the command line with a -command which runs the procedure and passes in the file. However, it seams as if the custom exporter type is not valid
"// Error: Invalid file type specified: OurCustomExporter // "

If I then go down to the Mel command prompt in the very same session that was started above and run the same procedure again it works perfectly.

Could it be that the procedure is trying to export a file before our CustomExporter has had a chance to autoload? If so, how would I get around this? Is there a wait command in mel that I could throw into the beginning of the procedure?

Thanks for the help.
AdamM

Robert Bateman
11-16-2010, 08:32 AM
Could it be that the procedure is trying to export a file before our CustomExporter has had a chance to autoload? If so, how would I get around this? Is there a wait command in mel that I could throw into the beginning of the procedure?

Probably. Either call loadPlugin, or use evalDeferred to run the script when maya is next idle.

AdamMax
11-17-2010, 02:52 AM
Thanks Robert..
loadPlugin blabla;
worked perfectly :)

CGTalk Moderation
11-17-2010, 02:52 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.