May 24, 2012

RandomColor Script

Hi,
I did a quick script to assign a random color to the objects present in the scene. I also added some functions to make it more 'convenient'. now, you can change the color of one/multiple objects, or inversely, disable single/all colors.

» Download RandomColor





 here you can find source of the main Script RandomColor_All :



# help      : set random color to All objects
import c4d
from random import randint
def randomColor():
    r = randint(0,255) / 256.0  
    g = randint(0,255) / 256.0  
    b = randint(0,255) / 256.0
    color = c4d.Vector(r,g,b)
    return color
def myObjects(op):
    if op==None: return None
    if op.GetDown(): return op.GetDown()
    while not op.GetNext() and op.GetUp():
        op = op.GetUp()
    return op.GetNext()

def main():
    ls = []
    obj = doc.GetFirstObject()
    if obj == None: return

    doc.StartUndo()
    while obj:
        cColor = randomColor()
        while cColor in ls:
            cColor = randomColor()
        ls.append(randomColor())
        obj[c4d.ID_BASEOBJECT_USECOLOR] = True
        obj[c4d.ID_BASEOBJECT_COLOR] = cColor
        doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
        obj = myObjects(obj)
     
    doc.EndUndo()
    c4d.EventAdd()
if __name__=='__main__':
    main()

3 comments:

  1. Very good article. I definitely love this website.
    Continue the good work!

    Also visit my webpage; coffee drinkers

    ReplyDelete
  2. This is very interesting, Thank for your contribution.
    Excuse my poor english, I'm from Spain :)
    Adiós amigo.

    ReplyDelete