Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create a File Node + Place2DTexture in Maya SDK

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ikeshet
4898 Views, 5 Replies

How to create a File Node + Place2DTexture in Maya SDK

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?

 

5 REPLIES 5
Message 2 of 6
sven_j
in reply to: ikeshet

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
ikeshet
in reply to: sven_j

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.

 

 

Message 4 of 6
singhk11
in reply to: ikeshet

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

Message 5 of 6
sven_j
in reply to: singhk11

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...

Message 6 of 6
michaelkdaw
in reply to: singhk11

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report