Pass a variable string from cmd to maya batch

Pass a variable string from cmd to maya batch

Anonymous
Not applicable
2,382 Views
7 Replies
Message 1 of 8

Pass a variable string from cmd to maya batch

Anonymous
Not applicable

Hi,

 

I'm using a script to do different polygonal operations on models via maya batch. I want to send a variable string via cmd to maya batch which will be used by the mel script (QA.mel) to name the material name same as the variable name. What will be the best way to implement it?

 

Thanks in advance.

0 Likes
Accepted solutions (1)
2,383 Views
7 Replies
Replies (7)
Message 2 of 8

rajasekaransurjen
Collaborator
Collaborator

Hi,

 

mayabatch -file File.ma -command "source QA.mel; QAproc("stringVariable");file -save"

 

Hope this will work, Otherwise share your script.

 

Best regards,
Rajasekaran Surjen.

Message 3 of 8

haggi_master
Advocate
Advocate

There are several ways to do it:

  • Simply restart the mayabatch every time you want to use it and give it the correct values
  • Implement a command port script which communicates with your mayabatch (at least I think it should be possible)
  • Implement a simple watch folder behaviour: Let the batch look in a special directory for a text file which contains the info you need, then save the info from the UI in this file. I think this is the simplest way to do it if you need a continously running batch job.
  • Implement a client server system (a little bit overdone for this problem I think).
Message 4 of 8

Anonymous
Not applicable

Thanks for the help. Can you please also tell how to access this variable in the script?

0 Likes
Message 5 of 8

rajasekaransurjen
Collaborator
Collaborator

Hi,

 

proc QAproc(string $strVar)
{
    print ("The Given Sting Variable is "+$strVar);
}

QAproc("AAAA");

 

 

Hope this example will help.....or share your script.

0 Likes
Message 6 of 8

Anonymous
Not applicable

Thanks for the reply but I'm not able to implement it in my script. I've attached my script and fbx file. Please have a look.

 

I want to rename the material to the name that I specify via cmd command.

 

mayabatch -command "source bottles.mel; glassMTL(""testName""); file -import -type ""FBX"" -mergeNamespacesOnClash true -rpr "":"" -options ""fbx"" ""D:/u00021296006064_hr.fbx""; file -rename ""D:/u00021296006064_hr.mb""; file -f -save  -options ""v=0;"" -type ""mayaBinary"";"

Appreciate your help! 🙂

 

Is there a way to pause at the end so we can read the error messages?

 

Regards.

0 Likes
Message 7 of 8

haggi_master
Advocate
Advocate
Accepted solution

I heavily recommend to keep the needed commandline as short as possible and execute a mel script. If you call your global proc the same as the script file, maya finds the procedure automatically e.g.

 

mayabatch -command "bottles(\"somestring\");"


And then you have a mel script called bottes.mel which contains a global proc called... well you guess it: bottles like this:

global proc bottles(string $argument)
{
    doAnything.....
}

In your case this could be:

global proc bottles(string $whatever)
{
    file -import -type "FBX" -mergeNamespacesOnClash true -rpr ":" -options "fbx" "D:/u00021296006064_hr.fbx"; 
    file -rename "D:/u00021296006064_hr.mb"; 
    file -f -save  -options "v=0;" -type "mayaBinary";
}

It is very much easier to modify and you do not have to care too much about masking the quotation marks (a double "" does not work, the second one has to be masked by a backslash: "\")

 

And for testing you can simply execute the mayabatch command in a commandline, then you will see the error messages.

Message 8 of 8

Anonymous
Not applicable

thanks a lot!!! 🙂

0 Likes