shader networks and EVAL command

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
  05 May 2012
shader networks and EVAL command

Hello everyone!

I have a quick question about the functionality of the "eval" command. Seems like there is some funny business with the way that it works- if you send out a few in succession, they mess up! Something to do with the way that maya processes multitasking, apparently. Am I right to think this? What is the correct way to send out evals one after the other? The following script will execute perfectly if you execute one line at a time, but will fail if you just send them all at once (enter on the num pad). Can anyone help me correct my syntax? The script should create a two-colored ramp, add it to the ambient color of a selected shading network, and have its Vcoord controled by a surfaceLuminance node (clamped at 1).

// Ambient
string $SD[] = `ls -sl`;
// cria uma rampa colorida
string $AmbRamp = `shadingNode -asTexture ramp`;
string $AmbRamp_placement = `shadingNode -asUtility place2dTexture`;
eval ("connectAttr " + $AmbRamp_placement + ".outUV " + $AmbRamp + ".uv;");
eval ("connectAttr " + $AmbRamp_placement + ".outUvFilterSize " + $AmbRamp + ".uvFilterSize;");

eval ("setAttr \"" + $AmbRamp + ".colorEntryList[2].color\" -type double3 0 0 0;") ;
eval ("setAttr \"" + $AmbRamp + ".colorEntryList[0].color\" -type double3 0.275 0.061875 0.061875;") ;
eval ("removeMultiInstance -break true " + $AmbRamp + ".colorEntryList[1];");
eval ("connectAttr " + $AmbRamp + ".outColor " + $SD[0] + ".ambientColor;");

// cria um node de clamp (max de 1) e poe no Vcoord da rampa
string $C = `shadingNode -asUtility clamp`;
eval ("connectAttr -f " + $C + ".outputR " + $AmbRamp + ".vCoord ;");
eval ("setAttr \"" + $C + ".maxR\" 1;");

// cria um surfaceluminance
string $SLu = `shadingNode -asUtility surfaceLuminance`;
eval ("connectAttr -f " + $SLu + ".outValue " + $C + ".inputR;");


Diego Velasco-De Armas
3D Artist / VFx Director --- Oca Filmes
TJB! / M&S / Spectacular ( WIP ) / Steampunk / Video
  05 May 2012
Is there any reason why you use the eval command? You can do it directly:

  string $AmbRamp = `shadingNode -asTexture ramp`;
  string $AmbRamp_placement =  `shadingNode -asUtility place2dTexture`;
  connectAttr ($AmbRamp_placement + ".outUV ") ($AmbRamp + ".uv"); 
 connectAttr ($AmbRamp_placement + ".outUvFilterSize")  ($AmbRamp + ".uvFilterSize")

Or in python with pymel (actually I didn't test the code, but it should be work - more or less):
import pymel.core as pm
 texNode = pm.shadingNode("ramp", asTexture = True)
 placeNode = pm.shadingNode("place2dTexture", asUtility=True)
 placeNode.outUvFilterSize >> texNode.uvFilterSize
 placeNode.outUV >> texNode.uv
__________________ -
  05 May 2012
Haggi is right, never use eval like this for simple string catenation. It's completely redundant, obfuscates your code and masks the actual problem behind an innocent eval.
eval is NOT the issue here, you should still see the same behaviour even without eval.

The problem is that Maya performs certain operations to do with creating nodes and setting attributes at it's own pace (for efficiency reasons presumably), and this is nowhere more evident than with color ramps (and any node that has similar dynamic entries).

You can't create/delete an entry from a color ramp until it has finished creating and initializing the node completely, you will have to evalDeferred your edits.

The reason it works when you input line by line is that Maya completes execution and returns to idle after every line.
  05 May 2012
Mel is not complicated, but it does have its specific issues. For example, I donīt think I ever saw a list (or even a general suggestion) of when to use eval, or evalDeferred. Anyway, I guess practice and experience would do the trick. Thanks for adding to mine!


Diego Velasco-De Armas
3D Artist / VFx Director --- Oca Filmes
TJB! / M&S / Spectacular ( WIP ) / Steampunk / Video
  05 May 2012
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 07:09 AM.

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