Assign image to materials diffuse

Assign image to materials diffuse

Anonymous
Not applicable
1,232 Views
4 Replies
Message 1 of 5

Assign image to materials diffuse

Anonymous
Not applicable

Hi, I'm trying to assign a file to the "Diffuse" of a material. So far I've only managed to assign it to the material with the name "test1". I want to make it so that it will assign a file to whatever material I have selected instead.

 

Better yet, I want to make it assign to the selected object (in the scene)'s material. How can I do this?

 

createRenderNodeCB -as2DTexture "" file "defaultNavigation -force true -connectToExisting -source %node -destination test1.diffuse; window -e -vis false createRenderNodeWindow;";

 

AEfileTextureBrowser "AEassignTextureCB file1.fileTextureName" "file1" image;

0 Likes
Accepted solutions (1)
1,233 Views
4 Replies
Replies (4)
Message 2 of 5

stuzzz
Collaborator
Collaborator
Accepted solution

I haven't write a melscript for ages but here's the python's code.

Someone will probably translate it. 

filePath = "myfilepath.jpg"
shapes = cmds.listRelatives(cmds.ls(sl=True), s=True)
SGs = cmds.listConnections(shapes[0], type='shadingEngine' )
shaders = cmds.listConnections("%s.surfaceShader" % SGs[0], s=True)

fileNode = cmds.shadingNode("file", asTexture=True, isColorManaged=True)
cmds.connectAttr('%s.outColor' %fileNode, '%s.color' % shaders[0])

cmds.setAttr("%s.fileTextureName" % fileNode, filePath, typ="string")

for the sake of simplicity, I did not catch any error or array content. 

 

Message 3 of 5

Anonymous
Not applicable

Thank you so much Stuzzz! How do you set a file to diffuse though? That's the last hurdle I'm facing. When I run that script it sets a file to Color

image.png

0 Likes
Message 4 of 5

stuzzz
Collaborator
Collaborator

My bad, for some reason i thought about the color attribute.

For the  diffuse you need to switcht the 6th line with

 

 

cmds.connectAttr('%s.outAlpha' %fileNode, '%s.diffuse' % shaders[0])

 

The only connection to the diffuse has to be scalar value (1 component), you cannot connect the color which is RGB (3 components). That the reason why I connected the alpha.

0 Likes
Message 5 of 5

Anonymous
Not applicable

You are a life saver man. Cheers!