cwisbg

colorRandomizerv_0.4

Jan 26th, 2012
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. """___________________
  2.    colorRandomizer
  3.    version_0.4
  4.    
  5.    cwisbg
  6.    Brandon Gillespie
  7.    updated: 1/27/2012
  8. ______________________      
  9. """
  10. from pymel.core import*
  11. import random as r
  12. def tinter(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.         connectAttr('{0}_ramp.outColor'.format(a),'{0}.color'.format(sl[0]), f=1)
  18.     except:
  19.         connectAttr('{0}_ramp.outColor'.format(a),'{0}.diffuse'.format(sl[0]), f=1)
  20.     matShapes = listConnections(sl[0], t='shadingEngine', d=1)
  21.     SG_mesh = listConnections(matShapes[0],t='shape', s=1)
  22.     mesh_shapes = []
  23.     for i in SG_mesh: # Get shape and add attributes for color
  24.         randoC = r.random()
  25.         mesh_shapes.append(listRelatives(i,s=1))
  26.         checkColor = attributeQuery('color',node = i ,ex=1)
  27.         if checkColor:
  28.             pass
  29.         else:
  30.             addAttr(i, ln = 'color', at='double', min=0, max=1)
  31.             setAttr('{0}.color'.format(i),e=1, keyable=1)    
  32.             setAttr('{0}.color'.format(i), randoC)
  33.     z = 0  
  34.     for i in mesh_shapes:# connect shapes to switch node
  35.         connectAttr('{0}.instObjGroups[0]'.format(i[0]), '{0}_colorSwitch.input[{1}].inShape'.format(a,z))  
  36.         z += 1
  37.     z = 0      
  38.     meshLength = len(SG_mesh)  
  39.     for mesh in SG_mesh:# connect color attribute to switch node
  40.         connectAttr(mesh+".color",'{0}_colorSwitch.input[{1}].inSingle'.format(a,z),f=1)
  41.         z += 1    
  42. sl = selected()
  43. for i in sl:
  44.     tinter(i)
Advertisement
Add Comment
Please, Sign In to add comment