Skip to content

Instantly share code, notes, and snippets.

View fwilleke80's full-sized avatar
💭
Mostly inactive, sometimes active, I really don't feel like updating my status

Frank Willeke fwilleke80

💭
Mostly inactive, sometimes active, I really don't feel like updating my status
View GitHub Profile
@fwilleke80
fwilleke80 / c4d-hierarchy-iterating-generators.py
Last active April 9, 2018 09:12
[C4D] This script contains two generator functions that allow you to effortlessly iterate over objects hierarchies in Cinema 4D, as well as some simple testing code that will iterate the hierarchy of the current document (starting form the selected object), and print it to the console.
import c4d
"""
This script demonstrates two generator functions, AllChildren() and AllParents().
To test this, use any scene with a reasonably complex hierarchy, select any one object and run the script.
"""
def AllChildren(startOp, maxDepth = 0, currentRecursionDepth = 1):
"""Yield all objects that are part of startOp's child hierarchy.
Set maxDepth to a value != 0 to restrict recursion to a certain depth.
@fwilleke80
fwilleke80 / printcallstack.py
Last active April 9, 2018 14:16
This function prints out the callstack, starting from top calling function down to the function the call came from.
import inspect
def PrintCallstack(printArgs = False):
"""Print the callstack, starting from top calling function
down to the function that called PrintCallstack().
To also print out all arguments passed to the calling function,
including the arguments' values, set printArgs to True.
Careful, this can get quite overwhelming.
"""
@fwilleke80
fwilleke80 / c4d-restart-cinema.py
Last active July 17, 2019 10:05
[C4D] A really tiny script that restarts Cinema 4D
"""
Name-US:Restart Cinema 4D
Description-US:Restart Cinema 4D (hold SHIFT to skip the question)
Name-DE:Cinema 4D neustarten
Description-DE:Cinema 4D neustarten (SHIFT halten, um die Abfrage zu überspringen)
"""
import c4d
@fwilleke80
fwilleke80 / c4d-close-all-documents.py
Last active July 17, 2019 10:04
Close all open documents in Cinema 4D, even the unsaved ones, skip the Save question for each one
"""
Name-US:Close all documents
Description-US:Close all open documents, even the unsaved ones (hold SHIFT to skip the question)
Name-DE:Alle Dokumente schließen
Description-DE:Schließt alle Dokumente, auch die ungespeicherten (SHIFT halten um die Abfrage zu unterdrücken)
"""
import c4d
@fwilleke80
fwilleke80 / getc4dresid.py
Last active November 6, 2018 08:59
Put this script into "Cinema 4D Rx/plugins" and run it from the command line to find free resource IDs for a plugin in a certain module. Call with "-h" command line option to get help.
#!/usr/bin/python
#
# Example calls:
#
# python getc4dresid.py --module lbwss --plugin osurfacespread
# Get some free resource IDs from plugin "Osurfacespread" in module "lbwss"
#
# python getc4dresid.py --module cinea4dsdk --plugin oatom --limit 1
# Get the next free resource ID from plugin "Oatom" in module "cinema4dsdk"
@fwilleke80
fwilleke80 / c4d-r20-multiinstance-test.py
Last active July 17, 2019 11:36
[C4D] Create a bunch of coloured object clones using the R20 Multi Instance feature
"""
Name-US:Multi Instance test
Description-US:Create a bunch of colored object clones using the R20 MultiInstance feature
"""
import c4d, time
COUNT_X = 200
COUNT_Z = 300
MARGIN = 150.0
NOISE_HEIGHT = 1200.0
@fwilleke80
fwilleke80 / c4d-pytag-polygonarea.py
Last active May 6, 2020 07:45
[C4D] Copy this code into a Python tag and it will calculate the area of any PolygonObject it is attached to.
import c4d
def calc_polygon_area(polygon, points, mtx = c4d.Matrix()):
"""Calculate the area of a polygon
@param polygon A CPolygon object
@param points List of c4d.Vector with point positions
@param mtx Optional globla matrix of the polygon object, to take object scale into account
@return The area of the polygon
"""
# Calculate area for the triangular polygon
@fwilleke80
fwilleke80 / c4d-save-as-template.py
Last active July 17, 2019 10:06
[C4D] Save current document as template. Like the built-in script, just better, and in Python.
"""
Name-US:Save as template
Description-US:Saves the current document as template (hold CTRL to remove existing template, hold SHIFT to skip question dialog)
Name-DE:Als Template speichern
Description-DE:Speichert das aktuelle Dokument als Template (CTRL gedrückt halten um vorhandenes Template zu entfernen, SHIFT gedrückt halten um Abfrage zu überspringen)
"""
import os
import c4d
@fwilleke80
fwilleke80 / c4d-create-random-scene.py
Last active July 17, 2019 11:12
[C4D] A nicely customisable Python script that creates complex random scene hierarchies in Cinema 4D. Good for performance testing in cases where number of objects is an issue.
"""
Name-US:Create random scene...
Description-US:Create random scene (hold SHIFT to use previous settings, hold CTRL to forget previous settings)
"""
import sys
import time
import json
import random
import c4d
@fwilleke80
fwilleke80 / c4d-document-to-json.py
Last active January 9, 2024 09:21
[C4D] Export objects and tags of a document to a serialised JSON file
"""
Name-US:Export document as JSON
Description-US:Export document to JSON
"""
import c4d
import json
def serialize_data(data):
"""Serialize special data types