FORUMS: list search recent posts

MEL Scripting

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Moss
MEL Scripting
on Jul 7, 2011 at 7:49:30 pm

Hi,
I'm writing some code to automate something for me.
The part im stuck on is giving two variables a value:

$projectDir = Curent Project

$projectName = Current Scene

How do i tell it to save a variable as the Current project path and another as the current scene file?

I can't hardcode in the variable values, becuase they willbe diffrent for diffrent users and/or current projects.

Any ideas?

Thanks


Return to posts index

Steve Sayer
Re: MEL Scripting
on Jul 11, 2011 at 2:21:18 pm

There are query commands that will give you this information.

Try:
file -q -sceneName -shortName;
workspace -q -active;
for the scene name (minus the path), and the project folder (I think).

Check the docs of these two commands (file, workspace) for more options/details.

-Steve


Return to posts index

Mike Moss
Re: MEL Scripting
on Jul 11, 2011 at 6:47:34 pm

Hi, thanks! I got it!

Would you happen to know whats wrong with this line of code...?

system("start c:/users/mike/documents/maya/scripts/rar.exe a -m3 -ed –rn " + $currentSceneName + " " + $projectPath);

I'm trying to run winrar from mel, it should run winrar, and rename the .rar file to $currentSceneName and place it in the $projectPath directory.

The error it returns is syntax error, i cant seem to get the right syntax for this. This is the last line of code i need!


Return to posts index


Steve Sayer
Re: MEL Scripting
on Jul 11, 2011 at 7:01:37 pm

Sorry, can't be sure what the problem is. Do you know if the error is coming from WinRAR, from Windows, or from Maya?

I see some flags after the rar.exe command, and most of them have dashes in front of them (e.g. '-m3'), but the 'a' flag does not. Should it have one?

Also, check the values of $currentSceneName and $projectPath to see whether they contain precisely correct information. For example, maybe there's a slash missing at the end... or maybe there's one too many?

Hope something in there helps.

-Steve


Return to posts index

Mike Moss
Re: MEL Scripting
on Jul 11, 2011 at 7:21:46 pm

the "a" is correct (according to the winrar command help file) it should be left just the way it is.

The variables are also correct, i tested them using print $currentSceneName and both return the correct values.

I believe the problem stems from Maya.. something, the placement of the variables, the quotes is causing it to not run properly.

If i re-write the code without the variables and hardcode the path and scene name, then it works just fine. but when i do that, the entire line is in " "'s not just parts of it.


Return to posts index

Steve Sayer
Re: MEL Scripting
on Jul 11, 2011 at 8:42:43 pm

Hmm, okay.

Well, the rest of it looks okay to me. Except, maybe... when I look at your code here on the COW, it seems like the character in front of the 'rn' flag is slightly different than the others. It's as if one is a dash, while the others are hyphens.

Not sure if this is just a COW thing or if that difference is real and in your original code. If so that might be causing the problem.

Bit of a long shot, but I'm afraid I'm out of other ideas. Impossible to thoroughly troubleshoot this sort of thing remotely.

Good luck,

-Steve


Return to posts index


Steve Sayer
Re: MEL Scripting
on Jul 12, 2011 at 2:41:17 pm

You know... going back to this, I think the error might stem from the fact that your variables contain slashes (due to paths).

It's okay for the slashes to exist in the first part of your command, because they are enclosed in quotes. But when the variables get concatenated, it may be that Maya chokes on their slashes.

You could try adding escape characters to those variables when you store them, or experiment with the encodeString command.

Alternately, maybe the system command is choking on the slashes (or on any spaces in your path names...?). You could correct this by adding quotes (which you would have to escape) into the string you send out as a system command.

I'm not sure about either of these; just taking more guesses.

-Steve


Return to posts index

Mike Moss
Re: MEL Scripting
on Jul 11, 2011 at 9:03:55 pm

i double checked, looks like just a cow thing.

Thanks for trying. :)


Return to posts index

Mike Moss
Re: MEL Scripting
on Jul 11, 2011 at 9:38:23 pm

Since i can not figure out the right syntax for that, i've decided to take another approch, Which of course, returns another error!

"An array expression element must be a scalar value"

I have two variables that need to be written to a .txt file.

The name of the scene - $currentSceneName
List of cameras - $cameras

Here is the line of code that gives me the error

string $myStrArray[] = {$currentSceneName, $cameras};

I narrowd it down to the $cameras variable. (if i remove that and only use $currentSceneName then it works fine. If i only use $cameras then i get an error.

This is the code that deals with the $cameras variable.

$cameras = `ls -type "camera"`;
for( $cam in $cameras )
{
}


I've tried declaring the $cameras as a string and as an array
i.e. string $cameras & string $cameras[]

Both no go.

Any ideas on this ?


Return to posts index


Steve Sayer
Re: MEL Scripting
on Jul 12, 2011 at 2:46:14 pm

Check my earlier reply for another possibility re: the original code.

As for this version, I get a different error than you do. I get "cannot convert data of type string[] to type string," which makes sense to me: you are trying to take an entire array ($cameras) and use it to fill in a single element in another array ($myStrArray[1]).

Try looking into the appendStringArray command instead.

Although, again, I am not getting the same error, and I'm not sure why.

-Steve


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]