Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """___________________
- colorRandomizer
- version_0.4
- cwisbg
- Brandon Gillespie
- updated: 1/27/2012
- ______________________
- """
- from pymel.core import*
- import random as r
- def tinter(a):
- shadingNode('singleShadingSwitch', au=1, n = '{0}_colorSwitch'.format(a))
- shadingNode('ramp', at=1, n = '{0}_ramp'.format(a))
- connectAttr('{0}_colorSwitch.output'.format(a), '{0}_ramp.vCoord'.format(a),f=1)
- try:
- connectAttr('{0}_ramp.outColor'.format(a),'{0}.color'.format(sl[0]), f=1)
- except:
- connectAttr('{0}_ramp.outColor'.format(a),'{0}.diffuse'.format(sl[0]), f=1)
- matShapes = listConnections(sl[0], t='shadingEngine', d=1)
- SG_mesh = listConnections(matShapes[0],t='shape', s=1)
- mesh_shapes = []
- for i in SG_mesh: # Get shape and add attributes for color
- randoC = r.random()
- mesh_shapes.append(listRelatives(i,s=1))
- checkColor = attributeQuery('color',node = i ,ex=1)
- if checkColor:
- pass
- else:
- addAttr(i, ln = 'color', at='double', min=0, max=1)
- setAttr('{0}.color'.format(i),e=1, keyable=1)
- setAttr('{0}.color'.format(i), randoC)
- z = 0
- for i in mesh_shapes:# connect shapes to switch node
- connectAttr('{0}.instObjGroups[0]'.format(i[0]), '{0}_colorSwitch.input[{1}].inShape'.format(a,z))
- z += 1
- z = 0
- meshLength = len(SG_mesh)
- for mesh in SG_mesh:# connect color attribute to switch node
- connectAttr(mesh+".color",'{0}_colorSwitch.input[{1}].inSingle'.format(a,z),f=1)
- z += 1
- sl = selected()
- for i in sl:
- tinter(i)
Advertisement
Add Comment
Please, Sign In to add comment