Skip to content

Instantly share code, notes, and snippets.

'''
Create materials for all Objects Polygon Selection Tags in Cinema 4D using Python API.
Author: Mike Udin
Website: mikeudin.net
Tutorial: https://youtu.be/mJcL6i0SCtY
'''
import c4d
@MikeUdin
MikeUdin / generate_random_color.py
Created August 30, 2022 09:30 — forked from adewes/generate_random_color.py
A small Python script to generate random color sequences, e.g. for use in plotting. Just call the "generate_new_color(existing_colors,pastel_factor)" function to generate a random color that is (statistically) maximally different from all colors in "existing_colors". The "pastel_factor" parameter can be used to specify the "pasteliness"(?) of th…
import random
def get_random_color(pastel_factor = 0.5):
return [(x+pastel_factor)/(1.0+pastel_factor) for x in [random.uniform(0,1.0) for i in [1,2,3]]]
def color_distance(c1,c2):
return sum([abs(x[0]-x[1]) for x in zip(c1,c2)])
def generate_new_color(existing_colors,pastel_factor = 0.5):
max_distance = None
import c4d
from c4d import gui
# In this video let's talk how to create layers,
# apply it to objects and change it attributes with Cinema 4D Python SDK.
# Check out tutorial here:
# https://mikeudin.net/?p=8680
def GetFirstLayer(doc):
# localimport-v1.7.3-blob-mcw79
import base64 as b, types as t, zlib as z; m=t.ModuleType('localimport');
m.__file__ = __file__; blob=b'\
eJydWUuP20YSvutXEMiBpIfmeOLDAkJo7GaRAMEGORiLPUQrEBTVkumhSKK75Uhj5L+nHv2iSNpyf\
BiTXY+uqq76qpoqy+qsP/SyLIv4t+a5rVT0vleiU1o0XfSDdM8dEf95PFVNm9f96V28KstPQqqm71\
D4Kf9H/jZeNaehlzqq++Fqn49tv7PPvbJPw/PxrJvWvqqro2hZ1WJX1c924aUZDk0rVs0B2XK7adM\
d+s2bbVF8v15Fe3GIGi1OKrmk8BpJoc+yiy45L6aOQy5xScspWiWWNbaN0olTe4de0klMqmz7umoT\
dKarTiIbKv0B9aGMXSx6leN6Xu0U/u+4YatDLyNcK/E9gvOxCnBPR5hocBRQETVkiDrvRsozz4O6r\
AP/lWexsi8/VxAY64lVgH9AWIqOvNDyyv63SHCWmPcR9yoSl1oMOvpf1Z7FT1L2MggdbRa5va1C1F\
if5b6REcSi67Wl5EpXUqs/GtiFdkUejrv4VLXlEDqr4FiAnO2F0sVvfScyzjRFL+gHRAmJ4GmES2g\
"""
How to connect bezier spline points to objects
and control tangents with Python Tag in Cinema 4D.
View tutorial and get project files here
https://mikeudin.net/?p=7503
Author : Mike Udin
Web-site : mikeudin.net
import c4d
"""
Cinema 4D XPresso Python Node.
Resize Spline to two point separated segments.
Required ports:
SegmentCount(Integer)
Spline(Link)
"""
def main():
import c4d
from c4d import gui
#This script required Cinema 4D R20 and upper
def main():
objs = doc.GetActiveObjects(0)
if not objs:
import c4d,webbrowser
# Check tutorial and
# download project file here:
# https://mikeudin.net/?p=6900
#### 1 ####
#Python Tag placed User Data Button
def message(id,data):
if id == c4d.MSG_DESCRIPTION_CHECKUPDATE:
import c4d
def apply_axis(op,new_m):
loc_m = ~new_m * op.GetMg() #Get local matrix
op.SetAllPoints([loc_m.Mul(p) for p in op.GetAllPoints()])
op.SetMg(new_m)
op.Message(c4d.MSG_UPDATE)
import c4d
def main():
ps = op.GetAllPoints() #Points in Local coordinates List
m = op.GetMg() #Object Global Matrix
center = op.GetMp() #Local coordinates center: https://tinyurl.com/wed88cn
rad = op.GetRad() # Geometry radius: https://tinyurl.com/tb6vn64