CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-14-2012, 06:14 PM   #1
dvelasco
New Member
 
dvelasco's Avatar
portfolio
Diego Velasco-De Armas
Partner / 3D Artist / Effects TD
Oca Filmes
Sao Paulo, Brazil
 
Join Date: May 2009
Posts: 6
Send a message via MSN to dvelasco
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;");



Thanks!


--Diego
__________________
Diego Velasco-De Armas
3D Artist / VFx Director --- Oca Filmes
TJB! / M&S / Spectacular ( WIP ) / Steampunk / Video
 
Old 05-14-2012, 10:08 PM   #2
haggi
Expert
3d freelancer
 
Join Date: Apr 2004
Posts: 969
Is there any reason why you use the eval command? You can do it directly:

Code:
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):
Code:
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
__________________
www.renderwiki.com - www.openmaya.net
 
Old 05-15-2012, 10:42 AM   #3
NaughtyNathan
HighEnd3D deserter
 
NaughtyNathan's Avatar
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester, United Kingdom
 
Join Date: May 2008
Posts: 2,608
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.
 
Old 05-15-2012, 02:32 PM   #4
dvelasco
New Member
 
dvelasco's Avatar
portfolio
Diego Velasco-De Armas
Partner / 3D Artist / Effects TD
Oca Filmes
Sao Paulo, Brazil
 
Join Date: May 2009
Posts: 6
Send a message via MSN to dvelasco
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!

cheers


--Diego
__________________
Diego Velasco-De Armas
3D Artist / VFx Director --- Oca Filmes
TJB! / M&S / Spectacular ( WIP ) / Steampunk / Video
 
Old 05-15-2012, 02:32 PM   #5
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
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 10:35 PM.


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