Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to create a File Node + Place2DTexture in Maya SDK

How to create a File Node + Place2DTexture in Maya SDK

Anonymous
Not applicable
6,094 Views
5 Replies
Message 1 of 6

How to create a File Node + Place2DTexture in Maya SDK

Anonymous
Not applicable

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?

 

0 Likes
Accepted solutions (1)
6,095 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Accepted 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.

 

 

 

Message 3 of 6

Anonymous
Not applicable

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.

 

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

hi..do you know a python command for the same thing like create a file node +place2d texture ?

0 Likes
Message 5 of 6

Anonymous
Not applicable

Sorry, not sure if it exists. But you can execute mel commands with the python "eval" command.

 

https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/Maya-Tec...

0 Likes
Message 6 of 6

michaelkdaw
Enthusiast
Enthusiast

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')