Home Coding, Scripting, Shaders

Maya MEL - Pass on a String Variable inside a directory

Hello everyone,

I am a little stuck with string and variables. I understand how to create a string and how to pass it for the most basic use. However I am now trying to do the same thing in a more complicated scenario (for my basic knowledge) and I haven't been able to figure it out. I would love your help guys.

Basically I have like 50 animations and I want to be able to import them in and export our with almost the same name and I thought that it would be easier to call the animation if I had the name put it once and then that passes the name to all the other places where it needs it.

I want to make it a string so it can be an user input later.

Original Working Code:

//Import animation to the scene

file -import -type "FBX"  

  -ignoreVersion -ra true -mergeNamespacesOnClash false 

  -namespace "Dance_01" -options "fbx" -pr -importFrameRate true  

  -importTimeRange "override" "D:/Desktop/Animations/Dance_01.fbx";


///More lines of code......


// rename and Export Animation

file -force -options "fbx" -typ "FBX export" -pr -es "D:/Desktop/ProcessAnimations/Female_Dance_01";



Failed Attempt:

//Define the string variable

string $myFileName = "Dance_01";


//Import animation to the scene using the string variable

file -import -type "FBX"  

  -ignoreVersion -ra true -mergeNamespacesOnClash false 

  -namespace $myFileName = ("\"" + $myFileName + "\"") -options "fbx" -pr -importFrameRate true  

  -importTimeRange "override" $myFileName = ("D:/Desktop/Animations/" + $myFileName + ".fbx");


///More lines of code......


// rename and Export Animation

file -force -options "fbx" -typ "FBX export" -pr -es $myFileName = "(D:/Desktop/ProcessAnimations/Female_" + $myFileName + "\"");

I have been getting a syntax error but I am not really sure how to break it down to be able to pass on the string variable


If anyone has worked with this type of string variables, please I will appreciate your help.

Replies

  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter

    this line:

     -namespace $myFileName = ("\"" + $myFileName + "\"") -options "fbx" -pr -importFrameRate true 

    redefines $myFileName to be "Dance_01" - including quotation marks

    did you mean to do that? It's probably a bad idea to be redefining a variable inside a command.

    The same thing happens in this line:

    file -force -options "fbx" -typ "FBX export" -pr -es $myFileName = "(D:/Desktop/ProcessAnimations/Female_" + $myFileName + "\"");

    if you want to use the string variable here you don't need to have $myFileName = at the start. You can just have some brackets like this -es ("D:/Desktop/ProcessAnimations/Female_" + $myFileName +".fbx")

    I'm not sure why you keep adding "\"" on the end of the string in both these cases. You normally need a file extension there.

    What does the syntax error say?

Sign In or Register to comment.