11-11-2006, 10:21 PM
I'm writing some mel code that will simulate the connections made between a 2dtexture node and a file node, as can be seen when going into the hypershade and selecting file from the 2d textures list. When the file texture is made, there are about 18 connections made, hooking up the 2dtexture node to the file node. I looked at the script editor when i made the connection and there are a bunch of connectAttrs that do all of this linking up between the two nodes. Being that I'm trying to automate the creation of a bunch of these networks (i will eventually be hooking up a number of these file nodes to a layered texture) i was wondering if there was an easier way to get this default connection without having to run those 18 connectAttrs (such as a defaultNavigation command maybe?). If this is confusing, my apologies, its my first time really dealing with shader networks. Any and all help would be appreciated. Thanks in advance.
There probably is a defaultConnection (Ithink its called) flag to use. If there isn't, try this code. I created 400ish polyPlanes and textured them with brain slice MRI images. You apparently don't need to do ALL the connections manually if you don't want. I came up with this code before I heard of defaultConnection--note the commented outportions. --IIRC, I lifted it from one of the internal Maya scripts, hence the reference to "frame extension and texture cycling" in the comments:
[CODE]global proc string createSliceTexture(string $imageName)
string $lambert = `shadingNode -asShader lambert`;
string $lambertSG = $lambert + "SG";
sets -renderable true -noSurfaceShader true -empty -name $lambertSG;
connectAttr -f ($lambert+".outColor") ($lambertSG+".surfaceShader");
// Make a file texture.
string $fileTex = `shadingNode -asTexture file`;
/* string $placeTex = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($placeTex+".coverage") ($fileTex+".coverage");
connectAttr -f ($placeTex+".translateFrame") ($fileTex+".translateFrame");
connectAttr -f ($placeTex+".rotateFrame") ($fileTex+".rotateFrame");
connectAttr -f ($placeTex+".mirrorU") ($fileTex+".mirrorU");
connectAttr -f ($placeTex+".mirrorV") ($fileTex+".mirrorV");
connectAttr -f ($placeTex+".stagger") ($fileTex+".stagger");
connectAttr -f ($placeTex+".wrapU") ($fileTex+".wrapU");
connectAttr -f ($placeTex+".wrapV") ($fileTex+".wrapV");
connectAttr -f ($placeTex+".repeatUV") ($fileTex+".repeatUV");
connectAttr -f ($placeTex+".offset") ($fileTex+".offset");
connectAttr -f ($placeTex+".rotateUV") ($fileTex+".rotateUV");
connectAttr -f ($placeTex+".noiseUV") ($fileTex+".noiseUV");
connectAttr ($placeTex+".outUV") ($fileTex+".uv");
connectAttr ($placeTex+".outUvFilterSize") ($fileTex+".uvFilterSize");
// Hook the file texture to the color
connectAttr -f ($fileTex+".outColor") ($lambert+".color");
// Assign the source image.
// We use whatever is the default path.
// Enable frame extension and hardware texture cycling.
setAttr -type "string" ($fileTex+".fileTextureName") $imageName;
setAttr ($lambert +".transparency") 0.5 0.5 0.5;
11-18-2006, 04:56 PM
Thanks for the tip. I happened to be looking for something similar when I came across you post. Very helpful. Thanks.
11-18-2006, 04:56 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.