Last active
September 26, 2016 15:34
-
-
Save MikeUdin/b41a60c4f8f307ff8faf47908fb4cc2c to your computer and use it in GitHub Desktop.
Create Materials with Checkerboard shader for Selected Objects
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 randint | |
# Welcome to the world of Python | |
# Author: Mike Udin, | |
# Tutorial here http://mikeudin.net/?p=2915 | |
# 2016 | |
def randomColor(x,y): | |
r = randint(x,y) / 256.0 | |
g = randint(x,y) / 256.0 | |
b = randint(x,y) / 256.0 | |
return c4d.Vector(r, g, b) | |
def editMaterial(mat): | |
#mat[c4d.MATERIAL_COLOR_COLOR] = randomColor() | |
shader = c4d.BaseShader(c4d.Xcheckerboard) | |
mat[c4d.MATERIAL_COLOR_SHADER] = shader | |
shader[c4d.CHECKERBOARDSHADER_COLOR1] = randomColor(0,126) | |
shader[c4d.CHECKERBOARDSHADER_COLOR2] = randomColor(126,255) | |
mat.InsertShader(shader) | |
def main(): | |
objs = doc.GetActiveObjects(1) | |
if not objs: | |
gui.MessageDialog('No selected objects!') | |
return | |
doc.StartUndo() | |
for obj in objs: | |
tag = obj.GetTag(c4d.Ttexture) | |
if tag == None: | |
tag = obj.MakeTag(c4d.Ttexture) | |
doc.AddUndo(c4d.UNDOTYPE_NEW,tag) | |
if not tag.GetMaterial(): | |
mat_name = obj.GetName() + ' material' | |
mat = doc.SearchMaterial(mat_name) | |
if mat == None: | |
mat = c4d.Material(c4d.Mbase) | |
mat.SetName(mat_name) | |
editMaterial(mat) | |
doc.InsertMaterial(mat) | |
doc.AddUndo(c4d.UNDOTYPE_NEW,mat) | |
tag.SetMaterial(mat) | |
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