cwisbg

colorTinter version_2

Feb 1st, 2012
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. """___________________
  2.    colorTinter
  3.    version_2
  4.    
  5.    cwisbg
  6.    Brandon Gillespie
  7.    2/1/2012
  8. ______________________      
  9. """
  10. from pymel.core import*
  11. import random as r
  12. def tinterStg1(a):
  13.     shadingNode('singleShadingSwitch', au=1, n = '{0}_colorSwitch'.format(a))
  14.     shadingNode('ramp', at=1, n = '{0}_ramp'.format(a))
  15.     connectAttr('{0}_colorSwitch.output'.format(a), '{0}_ramp.vCoord'.format(a),f=1)
  16.     try:
  17.         miaDiffuse = listConnections('{0}.diffuse'.format(sl[0]), p=1)
  18.     except:
  19.         miaDiffuse = 0
  20.     try:
  21.         otherColor = listConnections('{0}.color'.format(sl[0]), p=1)
  22.     except:
  23.         otherColor = 0
  24.     if otherColor:
  25.         colorConnections = listConnections('{0}.color'.format(sl[0]),c=1)[0][1]
  26.         connectAttr('{0}_ramp.outColor'.format(a),'{0}.colorGain'.format(colorConnections), f=1)  
  27.     elif miaDiffuse:
  28.         colorConnections = listConnections('{0}.diffuse'.format(sl[0]),c=1)[0][1]
  29.         connectAttr('{0}_ramp.outColor'.format(a),'{0}.colorGain'.format(colorConnections), f=1)
  30.     else:
  31.         try:
  32.             connectAttr('{0}_ramp.outColor'.format(a),'{0}.color'.format(sl[0]), f=1)
  33.             print 'there'
  34.         except:
  35.             connectAttr('{0}_ramp.outColor'.format(a),'{0}.diffuse'.format(sl[0]), f=1)
  36.             print 'here'  
  37.                
  38. def connector(a):
  39.     matShapes = listConnections(sl[0], t='shadingEngine', d=1)
  40.     SG_mesh = listConnections(matShapes[0],t='shape', s=1)
  41.     mesh_shapes = []
  42.     for i in SG_mesh:
  43.         randoC = r.random()
  44.         mesh_shapes.append(listRelatives(i,s=1))
  45.         checkColor = attributeQuery('color',node = i ,ex=1)
  46.         if checkColor:
  47.             print 'Already has color atribute'
  48.             pass
  49.         else:
  50.             addAttr(i, ln = 'color', at='double', min=0, max=1)
  51.             setAttr('{0}.color'.format(i), randoC)
  52.             setAttr('{0}.color'.format(i),e=1, keyable=1)    
  53.     x = 1
  54.     z = 0  
  55.     for i in mesh_shapes:
  56.         connectAttr('{0}.instObjGroups[0]'.format(i[0]), '{0}_colorSwitch.input[{1}].inShape'.format(a,z))  
  57.         z += 1
  58.     z = 0      
  59.     meshLength = len(SG_mesh)  
  60.     for mesh in SG_mesh:
  61.         connectAttr(mesh+".color",'{0}_colorSwitch.input[{1}].inSingle'.format(a,z),f=1)
  62.         z += 1
  63. """
  64. """        
  65. sl = selected()
  66.  
  67. tinterStg1(sl[0])
  68. connector(sl[0])
Advertisement
Add Comment
Please, Sign In to add comment