Skip to content

Instantly share code, notes, and snippets.

@MikeUdin
Created August 23, 2017 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeUdin/2f5871a610e12ff75b32f195d6ad6c4b to your computer and use it in GitHub Desktop.
Save MikeUdin/2f5871a610e12ff75b32f195d6ad6c4b to your computer and use it in GitHub Desktop.
Cinema 4D Apply Random Material
import c4d
from c4d import gui
from random import shuffle
#Welcome to the world of Python
def main():
objs = doc.GetActiveObjects(2)
if not objs:
gui.MessageDialog('Please select some objects!')
return
mats = doc.GetActiveMaterials()
if not mats:
gui.MessageDialog('Please select some materials!')
return
n,l = 0,len(mats)
doc.StartUndo()
for obj in objs:
n %= l
if n == 0: shuffle(mats)
tag = obj.MakeTag(c4d.Ttexture,obj.GetTags()[-1])
doc.AddUndo(c4d.UNDOTYPE_NEW,tag)
tag.SetMaterial(mats[n])
n += 1
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment