Adding a transparency map to a material using the python API?

Adding a transparency map to a material using the python API?

Anonymous
Not applicable
804 Views
1 Reply
Message 1 of 2

Adding a transparency map to a material using the python API?

Anonymous
Not applicable

how can I do this? Thanks.

0 Likes
805 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

To the poor souls that have this problem, where they load diffuse maps with alpha but the alpha is not connected, the following python snippet does the magic:

 

#newnodes is a list of nodes that you want to look for textures/materials, for example all nodes created while importing your model
filenodes = cmds.ls(newnodes, exactType='file')
    for fnode in filenodes:
        if cmds.getAttr(fnode+'.fileHasAlpha'):
            conns = cmds.listConnections(fnode, connections=True)
            matnode = None
            for i in range(len(conns)):
                if '.outColor' in conns[i]:
                    #assert (matnode == None)
                    matnode = conns[i+1]
                    break
            if matnode != None:
                cmds.connectAttr( fnode+'.outTransparency', matnode+'.transparency', force=True)

 Essentially, all it does is looks into the nodes created by importing your model for file nodes and checks their connections. If they have an outColor connection, they also try to apply an outTransparency. And that's it, really.

0 Likes