Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MEL: substitute & Co

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
hamsterHamster
720 Views, 6 Replies

MEL: substitute & Co

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.

Labels (2)
6 REPLIES 6
Message 2 of 7
mspeer
in reply to: hamsterHamster

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" "__";

 

 

Message 3 of 7

@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.

Message 4 of 7
mspeer
in reply to: hamsterHamster

Hi!

 

Checking the match command is correct, but

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

 

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

 

 

Message 5 of 7

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.

Message 6 of 7
mspeer
in reply to: hamsterHamster

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.

Message 7 of 7

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report