MEL: substitute & Co

hamsterHamster
Advisor
Advisor

MEL: substitute & Co

hamsterHamster
Advisor
Advisor

Beginner's question: why would substitute command suddenly work unpredictably? Or is it a bug just in my MEL interpreter?

print(`substitute "__" "b_CTRL_lipCorner_R__rotate_Z" "."` +"\n");
b_CTRL_lipCorner_R.rotate_Z

print(`substitute "." "b_CTRL_lipCorner_R.rotate_Z" "__"` + "\n");
___CTRL_lipCorner_R.rotate_Z

I've broken my eyes checking for errors till I realized that this is a buggy thing. Had to replace this with substituteAllString, which to my surprise has function syntax. Would gladly use Python, unfortunately some BonusTools support MEL only, learning MEL on the go.

Are there some lists on MEL commands that are known to be unreliable?


,,,_°(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.

Reply
Accepted solutions (1)
844 Views
6 Replies
Replies (6)

mspeer
Consultant
Consultant
Accepted solution

Hi!

This is the correct result.

Please keep in mind that regular expressions are used and "." means any character, so the first match is always at the first character.

Use brackets to use the "." character without any special meaning.

substitute "[.]" "b_CTRL_lipCorner_R.rotate_Z" "__";

 

 

0 Likes

hamsterHamster
Advisor
Advisor

@mspeerthank you!

Where can it be read about dot&co usage? The Maya MEL Reference entry on substitute points toward match command, where the Synopsis is following:

 

 

 

 

. 	Matches any single character
^ 	Matches (anchors) the expression to the start of a line
[...] 	Matches any one of the enclosed characters. A pair of characters separated by - matches any character lexically between the pair, inclusive. If the first character following the opening "[ " is a "^" any character not enclosed is matched. A - can be included in the character set by putting it as the first or last character.

 

 

 

 

 From this piece of information, plus what you said, alone it seems really illogical to have . and ^ for identical functionality, not to mention specific use of []. Following the paradigm, they could have used escape character syntax...... not.

After learning Python, from MEL beginners perspective, it seems so inconsistent and clumsy.


,,,_°(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

mspeer
Consultant
Consultant

Hi!

 

Checking the match command is correct, but

"^" and "." are not the same.

 

substitute ".he" "hellohehe" "__";
// Result: hell__he // 
substitute "^he" "hellohehe" "__";
// Result: __llohehe // 

 

 

hamsterHamster
Advisor
Advisor

Thanks @mspeer , I got it, the dot stands for any first character. Still, how did you figure out the brackets part?


,,,_°(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.

mspeer
Consultant
Consultant

Hi!

Not "any first", just "any" character.

The brackets are also mentioned in the description for the "match" command.

OK now I see, the link you provided is from Maya 2015, please check the latest documentation for the current Maya versions.

0 Likes

hamsterHamster
Advisor
Advisor

Sorry, what I meant was in context of initial example, got the first character because used "." without any other letter. Works like "?" in Unix/DOS.

And, you are right, I did not pay attention to which version was found by Google, as the native help.autodesk.com search gives too much hits; the synopsis in v.2022 is a little bit more descriptive, however, even with that update I wouldn't be able to figure this out on my own without seeing examples there. Therefore, thank you for the solution and other examples.


,,,_°(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