Instantly share code, notes, and snippets.

💭
Mostly inactive, sometimes active, I really don't feel like updating my status

Frank Willeke fwilleke80

View GitHub Profile
@fwilleke80
fwilleke80 / c4d-r20-multiinstance-test.py
Last active Oct 30, 2018
[C4D] Create a bunch of coloured object clones using the R20 Multi Instance feature
View c4d-r20-multiinstance-test.py
"""
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 / getc4dresid.py
Last active Nov 6, 2018
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.
View getc4dresid.py
#!/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-close-all-documents.py
Last active Oct 10, 2018
Close all open documents in Cinema 4D, even the unsaved ones, skip the Save question for each one
View c4d-close-all-documents.py
"""
Name-US:Close all documents
Description-US:Close all open documents, even the unsaved ones
Name-DE:Alle Dokumente schließen
Description-DE:Schließt alle Dokumente, auch die ungespeicherten
"""
import c4d
@fwilleke80
fwilleke80 / restartcinema.pyp
Last active Apr 18, 2018
[C4D] A really tiny command plugin that restarts Cinema 4D. Only 18 lines long. Python version. Optionally, place a file "restartcinema.tif" in the same folder where this script is located, to give it an icon.
View restartcinema.pyp
import os, c4d
class RestartMeCommand(c4d.plugins.CommandData):
def Execute(self, doc):
return c4d.RestartMe()
if __name__ == "__main__":
try:
path, file = os.path.split(__file__)
bmp = c4d.bitmaps.BaseBitmap()
@fwilleke80
fwilleke80 / printcallstack.py
Last active Apr 9, 2018
This function prints out the callstack, starting from top calling function down to the function the call came from.
View printcallstack.py
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-hierarchy-iterating-generators.py
Last active Apr 9, 2018
[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.
View c4d-hierarchy-iterating-generators.py
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 / c4d-listtagsonobject.py
Last active Apr 9, 2018
[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.
View c4d-listtagsonobject.py
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.
"""
def ListTagsOnObject(op):
resultStr = 'Tags on object "' + op.GetName() + '": '
@fwilleke80
fwilleke80 / c4d-messagetostring.cpp
Last active Jul 6, 2017
[C4D] Return the name of a message ID as string. Very handy to find out what messages you're receiving. Call this from any Message() function in the Cinema 4D API, and simply pass the message ID and message data pointer.
View c4d-messagetostring.cpp
#include "c4d_general.h"
#include "c4d_plugin.h"
#include "ge_sys_math.h"
#include "c4d_string.h"
#include "ge_prepass.h"
#include "c4d_baselist.h"
#include "c4d_commanddata.h"
#include "c4d_falloffdata.h"
#include "c4d_messageplugin.h"
#include "c4d_baseeffectordata.h"
@fwilleke80
fwilleke80 / c4d-hidedescription.cpp
Last active Jul 6, 2017
[C4D] Show or hide an element from a node's description
View c4d-hidedescription.cpp
/// Show or hide an element from a node's description
///
/// param[in] node The node whose description we're changing
/// param[in] descr The description we're changing
/// param[in] MyDescID The ID of the element
/// param[in] show Pass true to show, or false to hide
/// return False if an error occurred, otherwise true
static Bool ShowDescription(GeListNode *node, Description *descr, Int32 descID, Bool show)
{
AutoAlloc<AtomArray> ar;
@fwilleke80
fwilleke80 / c4d-matrix-target.cpp
Last active Mar 26, 2017
[C4D] Create a matrix that targets a position with an optional up vector.
View c4d-matrix-target.cpp
/// Align a matrix to a target, using an up vector
///
/// @param[in] pos The position we're targeting from
/// @param[in] targetPos The position we're targeting at
/// @param[in] upVector The up vector, to avoid gimbal lock. Defaults to +Y
/// @return A matrix with an offset of 'pos', targeting 'targetPos' with its Z axis.
static inline Matrix Target(const Vector &pos, const Vector &targetPos, const Vector &upVector = Vector(0.0, 1.0, 0.0))
{
Matrix m(DC); // New matrix. Don't call default constructor, as we're filling the values now anyway.
m.off = pos; // Set position