MEL basics - please help

MEL basics - please help

anita.wiatr
Explorer Explorer
1,016 Views
6 Replies
Message 1 of 7

MEL basics - please help

anita.wiatr
Explorer
Explorer

Hello, I'm a fairly young 3D artist with no experience with coding/scripting, I'm currently working on experiences for AR (scenes exported form maya as glb) and some functions like MotionPath Flow or extruding curves do not export, so I found a way to get similar effects with the animation by rigging meshes and attaching locators to the curve. Unfortunately it's a very long and time consuming process especially with things like ribbons or growing vines, so I wanted to create a command in MEL that would do it all for me (assign motionpath to selected curve and locator, break the u value connection of the motionpath, assign new expression to it that is dependable on 2 attributes of the curve). So the MEL command is:

 

pathAnimation -fractionMode true -follow true -followAxis x -upAxis y -worldUpType "vector" -worldUpVector 0 1 0 -inverseUp false -inverseFront false -bank false -startTimeU 45 -endTimeU 58;
disconnectAttr motionPathX_uValue.output motionPathX.uValue;
expressionEditor EE "motionPath" "uValue";
expression -s "motionPathX.uValue = curve1.Pos - curve1.Gap*X-1" -o motionPath -ae 1 -uc all ;

 

so if instead of X i fill in the numbers myself the command works - of course since i copy-pasted from script editor, but manually inserting the number of the next motionpath to be created doesn't save me any time at all, so my question is to anyone with a basic understanding of MEL that would be kind enough to answer: 

 

How am i supposed to phrase the commend so that the next motionpath automatically generates it's number "x" and then uses this number in all the other lines of the command and uses this number minus  1 "x-1" in the line "- curve1.Gap*x-1;"?

 

Kind regards,

Anita

0 Likes
Accepted solutions (1)
1,017 Views
6 Replies
  • MEL
Replies (6)
Message 2 of 7

hamsterHamster
Advisor
Advisor

There are several ways to cycle the x, one of those is  for cycle.  Taking as an example from your code, the line will look something like this:

 

for ( $x=0; $x<=10; $x++ ) {  // iterate x from 0 to 10 with step 1
    ...
    expressionEditor EE ( "motionPath" + $x ) "uValue" ; // commands withing brackets are executed before the line itself
    ...
}

 

 


,,,_°(O__O)°_,,,
Maya2019.1 @ Windows10 & GeForce GTX1080Ti

If the post was helpful, click the
 ACCEPT SOLUTION  button, so others might find it much more easily.

0 Likes
Message 3 of 7

anita.wiatr
Explorer
Explorer

Thank you so much for the reply and your help!

I tried changing the command as the example you've given but I must be doing something wrong as i'm only getting an error message of "Invalid use of Maya object "motionPath"."

I wrote it like this :

 

pathAnimation -fractionMode true -follow true -followAxis x -upAxis y -worldUpType "vector" -worldUpVector 0 1 0 -inverseUp false -inverseFront false -bank false -startTimeU 45 -endTimeU 58;
for ( $x=0; $x<=10; $x++ ) {
disconnectAttr (motionPath + $x)_uValue.output (motionPath + $x).uValue;
}
expressionEditor EE "motionPath" "uValue";
for ( $x=0; $x<=10; $x++ ) {
expression -s "(motionPath + $x).uValue = curve1.Pos - curve1.Gap*($x-1)" -o motionPath -ae 1 -uc all ;
}

 

What am I doing wrong?

0 Likes
Message 4 of 7

hamsterHamster
Advisor
Advisor
Accepted solution

Setting aside that I am not getting into what are you trying to achieve, the syntax itself is wrong, as you are skipping quotes.

 

 

...
disconnectAttr ("motionPath"+ $x +"_uValue.output") ("motionPath"+ $x +".uValue") ;
...

 

 

 .. thou, I am not sure about that underscore; if that line is causing an error, then find what is precise name of the attribute you are trying to disconnect.

Similarly:

 

 

...
expression -s ("motionPath"+ $x +".uValue = curve1.Pos - curve1.Gap*("+ $x +"-1)") -o motionPath -ae 1 -uc all ;
...

 

 

I believe, you don't need two cycles: the disconnection and expression creation can be done immediately one after another, within one for cycle.

 

If unsure about the brackets and quotes, use print command to ensure the resulting string will be correct:

$x = 1 ;
print("motionPath"+ $x +".uValue = curve1.Pos - curve1.Gap*("+ $x +"-1)") ;


,,,_°(O__O)°_,,,
Maya2019.1 @ Windows10 & GeForce GTX1080Ti

If the post was helpful, click the
 ACCEPT SOLUTION  button, so others might find it much more easily.

Message 5 of 7

anita.wiatr
Explorer
Explorer

Thank you so much!

I realize I'm lacking the very basic understanding of MEL language and that's why I'm struggling so much with it. 

Thank you so much for correcting me, it does work now! The only thing is that each time I click on it with another locator selected it generates exactly the same (lowest) x for all the lines so even though motionpath generated gets the next available number all the other lines still turn out as "motionPath0.uValue" so they come out as error, but i can just change lowest x myself manually each time for the next available number of motionpath to be generated and that works so it's already saving me so much time!

Thank you once again!

0 Likes
Message 6 of 7

hamsterHamster
Advisor
Advisor

That's ok - everyone was beginner at some point, I consider myself too. 😄 Here, read more about for cycle in Maya Help articles. And, my pardons, the numbers in for brackets were set JUST as an example, for you to change according the need.. I thought you will notice the comments after //.

Best wishes in your use of Mel/Python

 

 


,,,_°(O__O)°_,,,
Maya2019.1 @ Windows10 & GeForce GTX1080Ti

If the post was helpful, click the
 ACCEPT SOLUTION  button, so others might find it much more easily.

Message 7 of 7

anita.wiatr
Explorer
Explorer

Yes, I did notice the comments after, I tried to adjust it to my scene so x was supposed to be between 52 and 103 so i swapped 0 for 52 and 10 for 103, but each time I ran the command x came out as 52 😅 but i'm assuming it's just my complete lack of understanding how cycles are supposed to work, so I'm really grateful for the linked article, I'll study the cycles and hopefully figure it out! I've been using maya without using commands at all, but now that I've discovered how much time it can save me especially with repetitive tasks, I definitely want to learn more about it! 

0 Likes