View Single Post
# 2 24-09-2007 , 01:05 AM
t1ck135's Avatar
Registered User
Join Date: May 2004
Location: UK
Posts: 1,991
Nice challenge user added image
You're definitely on the right track there.

Dont know if you've got Maya 8.5+ but this little python script I've knocked up changes the transparency for the currently selected object's material.
To test it just create a new scene, add a sphere or similar, open the script editor and copy the following code in and run it:

Code:
def toggleTrans():
    # import and alias the relevant python libraries (only needed once in userSetup.py)
    # python libraries
    import maya.cmds as mc
    # get the currently selected object
    curSel = mc.ls(selection=True, dagObjects=True)
    # get the selections shading engine node
    curShader = mc.listConnections(curSel, source=True, type='shadingEngine')
    # get the current material node attached to it - note, this may not work on complex shaders and would need to be tested
    curMaterial = mc.listConnections(curShader, source=True, destination=False)
    # go through the returned nodes
    for item in curMaterial:
        # discard the transform node
        if mc.nodeType(item) != 'transform':
            # get the current transparency setting (quick hack here is just the red channel)
            curVal = mc.getAttr(item+'.transparency')
            # if its greater than zero then set it to zero (remove transparency)
            if curVal[0][0] > 0.0:
                mc.setAttr(item+'.transparency', 0.0, 0.0, 0.0, type='double3')
            # if its already zero then add some transparency
            else:
                mc.setAttr(item+'.transparency', 0.5, 0.5, 0.5, type='double3')
Now whenever you run the following command in the script editor it will change the transparency for the selected objects material:

Code:
toggleTrans()
You can also run it through Mel like so:

Code:
python("toggleTrans()");
I dont know how to add shelf items yet but if I can find some example code or something then I'll set it up user added image
Oh and it might be helpful to convert it to Mel so that you can play with it (or in case you cant run python).


Examples of bTraffic - a traffic animation tool for Maya
bFlocking - a tool for Maya 8.5+ to generate flocking and swarming behaviours
Jan/Feb Challenge 2007 Entry and W.I.P
May/Jun Challenge 2006 Entry and W.I.P
Mar/Apr Challenge 2006 Entry and W.I.P
Jan/Feb Challenge 2006 Entry and W.I.P
Nov/Dec Challenge 2005 Entry and W.I.P
Sep/Oct Challenge 2005 Entry and W.I.P
Jul/Aug Challenge 2005 Entry
www.flash-fx.net

Last edited by t1ck135; 24-09-2007 at 01:19 AM.