Created
August 23, 2017 15:02
-
-
Save MikeUdin/2f5871a610e12ff75b32f195d6ad6c4b to your computer and use it in GitHub Desktop.
Cinema 4D Apply Random Material
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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