PDA

View Full Version : Variables in sourcing


Pointyman
12-23-2012, 10:19 PM
Hi, having some trouble, would hope someone can help with this.

string $currentWorkspace = `workspace -dir "C:/Users/Pointyman/Desktop/Object Assets/"`;
string $sourceFile = "source \"$currentWorkspace+"/ModelGenerator/C"+$comboTypeID+$comboRaceID+$comboGenderID+$comboAgeID+"/"+$comboTypeID+$comboRaceID+$comboAgeID+"_FacialProportionsConfig.txt\" ;";

What I want to do is run a source file (with mel procedures inside) based on specified variables.

It's giving me syntax errors and I'm not sure how to arrange the appropriate code.

I've been looking at this site for reference. Though it works for an absolute directory, I want this code to be able to access different directories with the said file.
http://www.scriptswell.net/2010/02/mel-source-script-with-variable.html

gmask
12-24-2012, 03:03 PM
scratch that

zoharl
12-26-2012, 08:01 AM
+"/ModelGenerator

You are missing a backslash before all the quotation marks starting from this one, until the last one - not included. A string is defined between two quotations marks. If you want a quotation mark inside a string, then you must escape it with a black slash so the interpreter won't be confused.

To debug a string syntax, start with only a part of it, check the syntax, and add more parts gradually until you find the culprit.

gmask
12-26-2012, 02:59 PM
string $sourceFile = "source \"$currentWorkspace

Oh I think you are missing a plus sign before $currentWorkspace.

The way I like to construct long strings is to build it in sections.

string $myString="blah blah \""+$variable;
$myString+="\" blah blah"+$variable2;

zoharl
12-26-2012, 07:22 PM
Really? I prefer to do it in python using format, ticks inside quotation marks, or using a raw string.

http://forums.cgsociety.org/showthread.php?t=1044538

gmask
12-27-2012, 03:08 AM
Really? I prefer to do it in python using format, ticks inside quotation marks, or using a raw string.

http://forums.cgsociety.org/showthread.php?t=1044538

Uh yeah okay but clearly this thread is about building strings in mel?

Pointyman
12-28-2012, 07:49 PM
Ah ha! Thank you. I knew I was missing something. couldn't figure out :applause:

zoharl
12-28-2012, 07:55 PM
Uh yeah okay but clearly this thread is about building strings in mel?

Sure, in the micro. ;)
In the macro, however, we are here to help people, and sometimes they don't ask the right question (and my previous reply, of course, was meant for the OP, although it was addressed to you).

gmask
12-28-2012, 11:33 PM
sometimes they don't ask the right question.

I don't think this thread really fits that scenario

zoharl
12-29-2012, 05:22 AM
I think that every mel thread fits this scenario, especially those that pertain to the language itself, such as how do I nest expressions, how to format strings, how to query attributes, etc. I believe that half of the noob questions about mel would have resolved themselves by moving to python.

gmask
12-29-2012, 04:14 PM
I think that every mel thread fits this scenario,

lol.. yeah right.. :rolleyes:

ristopuukko
12-30-2012, 10:30 AM
I apologize but :

I believe that half of the noob questions about mel would have resolved themselves by moving to python.

Have you ever read the stuff you write?

"Half of the noob questions about python would have resolved themselves by moving to mel."

Do you see the analogy ?

/risto

zoharl
12-30-2012, 11:06 AM
Challenge accepted; I'll start (I didn't really do the statistics, just threw out some numbers, but I can find relevant posts if necessary).

1. 30% of mel noob questions are about nested expression. Why doesn't this intuitive expression work, and the answer is decompose it to several lines, and use back ticks to get an expression value.
Global solution: Move to python, and you can nest expressions all you want.

2. 10% qt on formatting a string. Usually the answer involves parenthesis or escaping.
Solution: Move to python, it has many more intuitive options to construct a string. Also string operations in general are more versatile.

3.20% qt. How can I pass arrays, vectors as parameters, can't do linear algebra, and I need external plugins for basic API operation such as querying if a point is inside a mesh.
Solution: Move to python. It has many intuitive extensions (especially through pymel), linear package such as NumPy, and a direct access to the API.

ristopuukko
12-30-2012, 11:11 AM
c'mon Z, don't take me ( or yourself ) so seriously.

/r

zoharl
12-30-2012, 12:13 PM
Of course... ;)
:beer:

zoharl
01-02-2013, 08:25 AM
No activity in the forum for three days. Did everyone take my advice and moved to python?? :surprised

gmask
01-02-2013, 02:43 PM
maybe nobody wants to talk to you :p

CGTalk Moderation
01-02-2013, 02:43 PM
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.