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 / 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 / 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 / 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-tag-show-dirty-checksums.pyp
Last active May 9, 2019 10:40
[C4D] A small Tag plugin that will output the most important dirty checksums for the object it's attached to into the console. Quite handy to check if an object keeps refreshing or rebuilding its cache. Simply attach the "Show Dirty Checksums" tag to an object and watch the Python console output.
import c4d
ID_SHOWDIRTYCHECKSUMSTAG = 1052821
class ShowDirtySumsTag(c4d.plugins.TagData):
def Init(self, node):
priorityData = node[c4d.EXPRESSION_PRIORITY]
if priorityData is not None:
@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 / 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-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-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