MEL: String syntax errors giving me a headache

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
MEL: String syntax errors giving me a headache

I don't care what anyone says - the way autodesk wrote the syntax for strings in MEL is extremely user-UNfriendly. It doesn't matter how many times I write code where a string has to be on a command line (or a variable inside a string) - I never get it right, never!

Today I'm having this issue with optionVars - which you might know are not written as standard variables with a dollarsign:
$temp = `optionVar -q "myOptVar"`;
		-align "left"
		-annotation "bla bla" 	
		-label "bla bla"  
		-offCommand "myCommand(0)" 
		-onCommand "myCommand(1)"
		-value $temp
Above works ofc - but it's an ugly way of writing the code and involves a totally unecessary use of a standard variable ($temp). Everything "can" be written on just one line at the value flag.
I've tried, tried and tried some more to incorporate the first line to the -value -flag of my checkbox and all I get is syntax errors.

So how do you write that query for the value flag properly?
-value (`optionVar -q "myOptVar"`) - NOPE

I've tried omitting the quote signs with backslashes and all but I'm not getting anywhere. And after god knows how much time I give up! It's not worth a more painful headache than I already have so I'll surrender and ask you guys here instead - I hope you don't mind. Thanks.
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
Old 03 March 2013   #2
Look on the bright side - that actually makes $temp necessary So you're not wasting a line.
Old 03 March 2013   #3
I guess the right word here is "abundant".
It's "necessary" for my code example but I know it can be written without having to declare a temp variable.
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
Old 03 March 2013   #4
This shouldn't be producing an error. There's nothing wrong with the syntax, e.g.

	-align "left"
	-annotation "bla bla" 	
	-label "bla bla"  
	-offCommand "myCommand(0)" 
	-onCommand "myCommand(1)"
	-value `optionVar -q "myOptVar"`

(although I do not recommend giving a control the same name as a built-in command, i.e. 'checkBox')

What line is the syntax error being produced on? Or rather, what's the code on that line.
Are you sure your optionVar is an int? Are you doing this via a script file and if so, does it have the proper line-ending encoding for your platform?
Old 04 April 2013   #5
Doesn't the control name need to be a string in ""?
In your example the last line would be:

As for what a command, you can do a whole bunch of stuff if you take time to get the syntax working. Here is an example of a mulitlayered aint pretty, but shows that you can do lots without defining anything before.
This command querys a value to define a varaible, runs a proc with that variable and edits a text field in the gui.

-c "string $defName = `textFieldGrp -q -text nodeName`; rigPro_attachColliders($defName); text -e -l $defName deformerName;"

Hopefully that helps.

EDIT: Oh wait, you want to set the initial value...hmm...I don't have any scripts that have done that without declaring a variable first. Which by no means says it can't be done...maybe I ran into the same issue before and did the same thinng you are questioning. Hmmm...I will keep an eye out for it.

Last edited by animatedfox : 04 April 2013 at 02:53 PM.
Old 04 April 2013   #6
Quote: oesn't the control name need to be a string in ""?

no, in command syntax (as opposed to function syntax), which is unique to MEL, you can omit quotation marks for strings.

It would probably help if the OP posted the whole code of the section that's giving him trouble. As previously stated, there's nothing wrong with the syntax per se, there's probably some small details that's been overlooked somewhere.
Old 04 April 2013   #7
Cool thanks for the clarification.
I love when picky languages like MEL have moments when they aren't picky!
I love it, I say!
Old 04 April 2013   #8
Well, it's a double-edged sword, really.

Because it deviates so much from the accepted programming idioms, "do it if you like, but really only if you feel like it. Except here, now it's totally different, except when its not".
Experienced programmers will just always put their strings in quotes and never notice (once they got used to the two-fold syntax, functional and command-like), but first-time scripters might get confused as to 'when and why' they need quotes on strings, especially when they switch to 'real' programming or scripting languages that enforce stricter (and thus more predictable) rules.
Old 04 April 2013   #9
He, he, he...
By love it...I meant I hate it...but find it endearing.
Now begin thread transformation to Mel bash-O-rama: GO!
Old 04 April 2013   #10
Why would I bash MEL? It's my main tool for getting things done, programming-wise, in Maya. It has its quirks, for example the backtick syntax. Seriously? Put accents around your code? Symbols that can't even be written out by themselves, they are only printed in conjuntion with another character, so I have to awkwardly shift-press the key (after I've found it) then hit something else, like space or something, to see it. Who designed that?.
But then again, given its environment, it's perfectly suited and capable. I don't care how much more powerful Python is. On a dirt road, a Volkswagen gets you just as far as a Lamborghini. Convenience aside, MEL gets the job done just as well.

So that's that. Back on topic please
Old 04 April 2013   #11
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 11:59 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.