Skip to content

Instantly share code, notes, and snippets.

@baku89
baku89 / Python Tag
Last active September 27, 2016 13:53
C4D: Make only nth child object visible
# Add User Data (ID=1) as Integer
# In python tag
def main():
b = op.GetObject()
idx = b[c4d.ID_USERDATA,1]
children = b.GetChildren()
for i, c in enumerate(children):
v = 2 if idx == i else 1
@Squid3d
Squid3d / Walking_with_yield.py
Created March 5, 2015 03:46
using yield to iterate c4d object/tag and materials
import c4d
def walk_objects(obj):
if obj:
yield obj
for x in walk_objects(obj.GetDown()): # happily fail on tags and materials
yield x
for x in walk_objects(obj.GetNext()):
yield x
@hanswillem
hanswillem / userDataButton.py
Last active September 27, 2016 14:21
Code to make use of the user data button
#put the code in a python tag
#add a user data button to the tag
import c4d
#user data button
def message(id, data):
if id == 17:
print "UserData-ID: ", data["descid"][1].id
@adewes
adewes / generate_random_color.py
Last active March 27, 2025 13:56
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
@yoavram
yoavram / client.py
Created December 21, 2012 08:41
Example of uploading binary files programmatically in python, including both client and server code. Client implemented with the requests library and the server is implemented with the flask library.
import requests
#http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
url = "http://localhost:5000/"
fin = open('simple_table.pdf', 'rb')
files = {'file': fin}
try:
r = requests.post(url, files=files)
print r.text
@990adjustments
990adjustments / Toggle-AntiAliasing.py
Created November 2, 2011 02:26
A quick Cinema 4d Python script to toggle anti-aliasing setting.
"""
Toggle-AntiAliasing
Copyright: Erwin Santacruz, www.990adjustments.com
Written for CINEMA 4D R12.016
Name-US: Toggle-AntiAliasing
Description-US: A quick toggle for anti-aliasing settings.
Make it a button for quick access
@rduplain
rduplain / gist:1249199
Created September 28, 2011 20:41
Get a module's docstring in Python without executing it.
import code
def get_module_docstring(filepath):
"Get module-level docstring of Python module at filepath, e.g. 'path/to/file.py'."
co = compile(open(filepath).read(), filepath, 'exec')
if co.co_consts and isinstance(co.co_consts[0], basestring):
docstring = co.co_consts[0]
else:
docstring = None
return docstring
@andreberg
andreberg / CINEMA 4D MinMax Class.py
Last active February 24, 2020 17:37
[CINEMA 4D: Python MinMax Class] Class for calculating various metrics from a list of vectors, such as min, max, radius, size and midpoint. #cinema4d #c4d #python #class #minmax #computergraphics #cg
class MinMax(object):
"""
Calculate various area metrics from a list of points,
such as min, max, midpoint, radius and size.
"""
def __init__(self):
super(MinMax, self).__init__()
FLOATMIN = sys.float_info[3]-1000 # workaround for underflow error
FLOATMAX = sys.float_info[0]
self.min = c4d.Vector(FLOATMAX, FLOATMAX, FLOATMAX)
@andreberg
andreberg / CINEMA 4D Python Plane Class.py
Last active October 26, 2020 17:30
[CINEMA 4D: Python Plane Class] Class representing a plane defined by position and normal vector. Can calculate point distance and line intersections. #cinema4d #c4d #python #class #plane #computergraphics #cg
class Plane(object):
"""Represents a plane defined by position and normal vector"""
def __init__(self, pos, n):
super(Plane, self).__init__()
self.pos = pos
self.n = n.GetNormalized()
if DEBUG: print "self.pos = %r, self.n = %r" % (pos, n)
def setN(self, newn):
self.n = newn.GetNormalized()
@andreberg
andreberg / CINEMA 4D Python Helpers.py
Last active July 12, 2025 14:55
[CINEMA 4D: Python Helpers Class] The Helpers class is collection of reusable methods from cgsociety, the Plugin Café and from my own scripts. #cinema4d #c4d #python #class #helpers #computergraphics #cg
class Helpers(object):
"""Contains various helper methods."""
def __init__(self, arg):
super(Helpers, self).__init__()
@staticmethod
def readConfig(filepath=None):
"""
Read settings from a configuration file.