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-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
@fwilleke80
fwilleke80 / sinusoid_plotter.py
Created May 4, 2021 13:53
C4D Sinusoid plotter: Copy code into a Python tag. It will move an object in circles and loops.
import c4d
import math
FREQUENCY_X = 2.5
FREQUENCY_Z = 1.8
OFFSET_X = 0.5
OFFSET_Z = 0.0
AMPLITUDE_X = 100.0
AMPLITUDE_Z = 100.0
MULTIPLY_Y = 20.0
@fwilleke80
fwilleke80 / get_list_of_selected_polygons.py
Last active March 7, 2022 16:31
This script prints the indices of the selected polygons of the active polygon object to the console.
import c4d
def main():
if op is None:
print("No object selected.")
return True
if op.GetType() != c4d.Opolygon:
print("Selected object is not a PolygonObject.")
return True
@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-list-tags-on-object.py
Last active September 17, 2019 14:28
[C4D] This script lists all tags attached to the selected object, by name and plugin ID. It also shows if a tag is visible or invisible.
"""
Name-US:List tags on object
Description-US:List all tags attached to the selected object, by name and plugin ID
"""
import c4d
"""
This script lists all tags attached to the selected object, by name and plugin ID.
It also shows if a tag is visible or invisible.
"""
@fwilleke80
fwilleke80 / c4d-is-inside-geometry.py
Last active August 19, 2019 13:01
[C4D] A function that uses GeRayCollider to determine whether a given position is inside a polygon object's volume or not. Only works reliably with closed polygon objects. Absolutely not optimised for speed (you would probably want to do the collider initialisation and position transformation elsewhere)
def isInside(pos, polyOp):
"""Check whether a given position is inside a (closed!) polygon object.
:param pos: A position to test for, in global space
:param polyOp: A PolygonObject
:return: True if pos is inside polyOp, otherwise False
"""
# Init GeRayCollider
collider = c4d.utils.GeRayCollider()
collider.Init(polyOp)
@fwilleke80
fwilleke80 / c4d-get-plugin-flags.py
Created July 18, 2019 10:48
[C4D] A function that returns a string with the plugin flags for the BasePlugin of a BaseList2D
def GetPluginFlags(bl):
"""Return string with all plugin flags of a given BaseList2D element
@param bl The BaseList2D element (e.g. BaseObject, BaseTag,
BaseVideoPost, BaseMaterial, BaseShader, et cetera)
@return A string containing all the identified plugin flags
"""
if bl is None:
return ''
@fwilleke80
fwilleke80 / c4d-get-plugin-name.py
Last active July 18, 2019 10:45
[C4D] A function that finds the name of a plugin by ID, and even works for builtin BaseList2D elements that are not registered plugins
def GetPluginName(pluginId, pluginType=c4d.PLUGINTYPE_ANY):
# Check if it's the ID of a registered plugin
foundPlugin = c4d.plugins.FindPlugin(pluginId, type=pluginType)
if foundPlugin is not None:
return foundPlugin.GetName()
# It's not the ID of a registered plugin, but might still be a builtin
# Try to allocate a new instance, and get type name
newObj = c4d.BaseList2D(pluginId)
if newObj is not None:
return str(type(newObj).__name__)
@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-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