CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-31-2013, 05:51 PM   #1
DeadlyNightshade
Plz...
 
DeadlyNightshade's Avatar
portfolio
Martin Dahlin
Jr. Technical Artist
King
Stockholm, Sweden
 
Join Date: Jul 2012
Posts: 898
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:
Code:
$temp = `optionVar -q "myOptVar"`; checkBox -align "left" -annotation "bla bla" -label "bla bla" -offCommand "myCommand(0)" -onCommand "myCommand(1)" -value $temp checkBox;
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-31-2013, 06:07 PM   #2
Panupat
Expert
 
Panupat's Avatar
portfolio
Panupat Chong
Thailand
 
Join Date: Feb 2004
Posts: 1,942
Look on the bright side - that actually makes $temp necessary So you're not wasting a line.
 
Old 03-31-2013, 06:46 PM   #3
DeadlyNightshade
Plz...
 
DeadlyNightshade's Avatar
portfolio
Martin Dahlin
Jr. Technical Artist
King
Stockholm, Sweden
 
Join Date: Jul 2012
Posts: 898
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-31-2013, 08:24 PM   #4
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
This shouldn't be producing an error. There's nothing wrong with the syntax, e.g.

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

(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-01-2013, 02:49 PM   #5
animatedfox
what the ?!?!
 
animatedfox's Avatar
portfolio
Benjamin Fox
Seat 43
USA
 
Join Date: Feb 2010
Posts: 895
Doesn't the control name need to be a string in ""?
In your example the last line would be:
"checkBox";

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 command...it 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.
~Ben

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-01-2013 at 02:53 PM.
 
Old 04-01-2013, 04:45 PM   #6
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
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-01-2013, 04:51 PM   #7
animatedfox
what the ?!?!
 
animatedfox's Avatar
portfolio
Benjamin Fox
Seat 43
USA
 
Join Date: Feb 2010
Posts: 895
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-01-2013, 05:40 PM   #8
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
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-01-2013, 06:09 PM   #9
animatedfox
what the ?!?!
 
animatedfox's Avatar
portfolio
Benjamin Fox
Seat 43
USA
 
Join Date: Feb 2010
Posts: 895
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-01-2013, 07:24 PM   #10
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
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-01-2013, 07:24 PM   #11
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 03:28 AM.


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