#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Shuffling Colors Between Objects (Python)


    Hi everyone,

    I'm new to Python and was wondering how I can randomly shuffle the colors of 3 objects in a scene. Say I have: a cylinder, cone and sphere, and assign a lambert to each one, how's it possible to have their colors switch when scrolling through the timeline?

    My instructor did something along the lines of this with 2 objects:
    sel=cmds.ls(sl=True)
    shape=cmds.ls(sl=True,dag=True,shapes=True)
    if len(sel)!=2:
    cmds.promptDialog(message='SELECT ONLY 2 Objects Dummy')
    cmds.error('select only 2 objects')

    sg1=cmds.listConnections(shape[0],d=True,s=False,type='shadingEngine')[0]
    sg2=cmds.listConnections(shape[1],d=True,s=False,type='shadingEngine')[0]

    cmds.sets(shape[0],e=True,forceElement=sg2)
    cmds.sets(shape[1],e=True,forceElement=sg1)

    and then used random.randint/shuffle







    I tried to follow it but wasn't able to get it to work. Can someone pls help me? Thank you.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Code:
    sel=cmds.ls(sl=True)
    shape=cmds.ls(sl=True,dag=True,shapes=True)
    if len(sel)!=3:
        cmds.promptDialog(message='SELECT EXACTLY 3 Objects Dummy')
        cmds.error('select 3 objects')
    
    (sg1, sg2, sg3,) = sgs = [cmds.listConnections(SHAPE,d=True,s=False,type='shadingEngine')[0] for SHAPE in shape]
    
    [cmds.sets(SHAPE,e=True,forceElement=SG) for (SHAPE, SG,) in zip(shape, sgs)]
    
    # now employ random.shuffle in some way
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo