# Printing strings 'internally' w/i an expression?

**URL:** https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306
**Category:** Maya
**Tags:** mel
**Created:** [April 5, 2002, 10:39am UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306 "2002-04-05T10:39:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![campbell](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@campbell](https://forum.highend3d.com/u/campbell)
#### Post date: [April 5, 2002, 10:39am UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/1 "2002-04-05T10:39:32Z")

</div>

This is likely to be stupidly simple.

I want to 'print' the contents of a string variable w/i an expression so i can use a variable to define the attribute that is being assigned in an expression:

$var = $obj ".attrib"  
$var = sin(time\*$feg)

...this, of course, just assigns a new string to $var.  
I want to ~print the contents of $var then and there, in situ where it stands in the expression so that it is interpretated as string of characters (namely an attrib address), not a variable.

Thankyou,  
C.

---

<div class="post-metadata">

### Author: ![campbell](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@campbell](https://forum.highend3d.com/u/campbell)
#### Post date: [April 8, 2002, 4:07am UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/2 "2002-04-08T04:07:07Z")

</div>

Too stupid to answer even?

.. for anyone who gives a flyers, you can do what i want to do by building up the expression statements as large string concatenations that you can provide as a variable to the expression command's -s flag. If you need to address only one varying obj, use the -o flag for a node base.

Still, i would love to know if/how you can dump variable contents at the location of a variable which is not situated in a context that expects to have its contents read (eg as command arguments). Or, id just love to know if this is a bent path im taking ....

Cheers,  
c.

---

<div class="post-metadata">

### Author: ![goggle](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@goggle](https://forum.highend3d.com/u/goggle)
#### Post date: [April 8, 2002, 2:03pm UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/3 "2002-04-08T14:03:02Z")

</div>

I don't know a whole lot of MEL, and I'm a little unclear on what you're trying to do, but perhaps the `eval` command bears experimenting with.

Taken directly from the Command Description Pages:

Command Name  
eval   
Synopsis  
eval  
 eval arg1 ... [argn] ]

ReturnValue  
The return value of argument.   
Description  
This statement is designed to allow execution of a command which is not known until runtime. It requires at least one argument, the first, which is the command to be executed.

Flags  
None

Examples

```
string $timeOfDay = "afternoon";

switch($timeOfDay) {
	case "morning":
	    $shape = "circle";
	    break;
	case "afternoon":
	    $shape = "sphere";
	    break;
	case "evening":
	    $shape = "cone";
	    break;
	default:
	    $shape = "cylinder";
} 

eval $shape -r 5; // create specified shape with radius 5.

// In the example above, the eval command has 3 arguments: the MEL
// variable $shape, the flag -r, and the number 5. Alternatively,
// the user can construct one string from the arguments and pass it
// to eval as one argument. Eg:

eval ($shape+"-r 5");
```

Related Commands  
evalDeferred, evalEcho, scriptJob

Hope this helps.

-James

---

<div class="post-metadata">

### Author: ![campbell](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@campbell](https://forum.highend3d.com/u/campbell)
#### Post date: [April 9, 2002, 4:48am UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/4 "2002-04-09T04:48:46Z")

</div>

Cheers for your response James,

Id sussed eval as a possibility before posting, but it wont provide, as it is 'designed to allow execution of a \_command\_ which is not known until runtime' ...which is not my situation, in anycase what command would it be? perhaps the magicCommand im after:

```
 a command, or syntactical arrangement, that will take the alphanumeric content of a variable and 'write' that into the location where such a command was called from ....so that when the script/exprsn is being interpreted it will read the instances of such 'magicCommand $variable' (or some syntax surrounding the $variable) as if i had explicitly typed the variable's content right there ...
```

again ..

expression syntax:  
node.attribute = whatever

$varying\_node = `sphere -r 2`; // outside of expression

// in expression editor:

$varying\_node\_attrib = $varying\_node[0] + ".ty";

magicCommand $varying\_node\_attrib = whatever

```
 ....i want some method of writing the contents of $varying\_node\_attrib to the very position it occupies ...so it would read/interpret as:

nurbsSphereX.ty = whatever

      ....so we make a valid expression statement, in this case the most recent created sphere will have the expression1 controlling it's ty.
```

Thats all. Nothing fancy. Someone please put me out of my misery! ![](http://208.179.92.68/forums/icons/frown.gif)

Thought i better add : eval is fine to use if your using the expression command, but thats not the issue here, i know how to provide commands with variables, as i said above my solution was to build stings to hand to the expression command's -s expression string. I just want to know if you can force a variable to write its contents to where it stands (like a print, but not to the script editor). I suspect its probably functionality that is simply not needed, but i just dont know it yet.

Thankyou kindly,  
C.

---

<div class="post-metadata">

### Author: ![goggle](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@goggle](https://forum.highend3d.com/u/goggle)
#### Post date: [April 9, 2002, 5:04pm UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/5 "2002-04-09T17:04:47Z")

</div>

how about:

setAttr $variable + ".ty " + $value  
or  
setAttr $variable.$attr $value ?

I know setAttr's arent the best way to set things but this should set the value of a variable's attributes.

I'm just groping in the dark now.

-James

---

<div class="post-metadata">

### Author: ![campbell](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@campbell](https://forum.highend3d.com/u/campbell)
#### Post date: [April 10, 2002, 3:46pm UTC](https://forum.highend3d.com/t/printing-strings-internally-w-i-an-expression/6306/6 "2002-04-10T15:46:13Z")

</div>

Thanks James,

Sure, but its a situation where variables are situated in the context of a command's argument - and expects to have its contents read (or concatenated into a string). I want to force a variable to dump its contents when it isnt necessarily being asked for (eval does pretty much fit the bill, but its expecting a command first up ...i just want to 'evaluate' a string and continue on reading along the rest of the statement [if the string didnt contain a ;, of course] ..ark!)

Im not having problems building variables into expression statements if i do it with the expression command... say if you use eval to build your expression string:

$var1 = `sphere -r 2`;  
$var2 = `polyCube`;  
eval("expression -s "" + $var1[0] + ".ty = " + $var2[0] + ".tx"");

I am more and more suspecting my question just doesnt make sense in the everyday handling of variables. Even if i do find out you can do what i want, it would probably be of little use anyway. Was just curious, tis all.

Appreciated your suggestions,  
c.
