Hi
I am unsure how to create a File Node with a Place2DTexture using the SDK.
MFnDependencyNode nodeFile;
MFnDependencyNode nodePlace2DTexture;
MObject objNodeFile = nodeFile.create("file", nodeFileName);
MObject objNodePlace2D = nodePlace2DTexture.create("place2dTexture", nodePlace2DName);
I am unsure how to connect the place2DTexture to the file Node.
Any ideas?
Solved! Go to Solution.
Solved by sven_j. Go to Solution.
To create a new node I usually use MDGModifier or MDagModifier. Call the CreateNode() method and after it the doit() method. Don't forget to call doit!
You can use the modifier also to connect attributes/plugs. To see how you have to connect it, just execute the operation by hand in Maya and look in the Script Editor(often it is good to activate "Echo All Commands" in the History menu of the Script Editor), you can see what mel operation Maya will do. Additionally you can open the Hypershade window and display your material with all connections. Actually the file node is connected with a lot of attributes from place2dTexture.
When I activate "Echo All Commands" then add a new file to the lambert1 material for the ambientColor, then the first mel call will be:
createRenderNodeCB -as2DTexture "" file "defaultNavigation -force true -connectToExisting -source %node -destination lambert1.ambientColor; window -e -vis false createRenderNodeWindow;";
So maybe it is easier for you to call this command in your source code. All you have to do is create a MString which contains the correct material name instead of "lambert1" and the correct attribute name instead of "ambientColor". You can use the MDGModifier/MDagModifier::commandToExecute() method or the static method MGlobal::ExecuteCommand().
The advantage is, if Autodesk will change the file node in the future, then this method should be automatically adjusted to that.
Thanks very much for the help -- I was doing it prior before with the MDGModifier but was having some issues -- ill try to use mel.
Sorry, not sure if it exists. But you can execute mel commands with the python "eval" command.
Hi,
In case it's useful, here's what I use as a python method for building a file node and an associated place2dTexture:
import pymel.core as pm def createFileTexture(fileTextureName, p2dName): tex = pm.shadingNode('file', name=fileTextureName, asTexture=True, isColorManaged=True) if not pm.objExists(p2dName): pm.shadingNode('place2dTexture', name=p2dName, asUtility=True) p2d = pm.PyNode(p2dName) tex.filterType.set(0) pm.connectAttr(p2d.outUV, tex.uvCoord) pm.connectAttr(p2d.outUvFilterSize, tex.uvFilterSize) pm.connectAttr(p2d.vertexCameraOne, tex.vertexCameraOne) pm.connectAttr(p2d.vertexUvOne, tex.vertexUvOne) pm.connectAttr(p2d.vertexUvThree, tex.vertexUvThree) pm.connectAttr(p2d.vertexUvTwo, tex.vertexUvTwo) pm.connectAttr(p2d.coverage, tex.coverage) pm.connectAttr(p2d.mirrorU, tex.mirrorU) pm.connectAttr(p2d.mirrorV, tex.mirrorV) pm.connectAttr(p2d.noiseUV, tex.noiseUV) pm.connectAttr(p2d.offset, tex.offset) pm.connectAttr(p2d.repeatUV, tex.repeatUV) pm.connectAttr(p2d.rotateFrame, tex.rotateFrame) pm.connectAttr(p2d.rotateUV, tex.rotateUV) pm.connectAttr(p2d.stagger, tex.stagger) pm.connectAttr(p2d.translateFrame, tex.translateFrame) pm.connectAttr(p2d.wrapU, tex.wrapU) pm.connectAttr(p2d.wrapV, tex.wrapV) return tex createFileTexture('fileOne', 'p2dOne')