Skip to content

Instantly share code, notes, and snippets.

View NiklasRosenstein's full-sized avatar
💭
I may be slow to respond.

Niklas Rosenstein NiklasRosenstein

💭
I may be slow to respond.
View GitHub Profile
@NiklasRosenstein
NiklasRosenstein / iconbutton.py
Last active January 22, 2019 17:02
IconButton class for the Python Cinema 4D API.
# Copyright (C) 2013, Niklas Rosenstein
# http://niklasrosenstein.de/
#
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#
# Changelog:
#
# 1.1: Corrected action msg for Command() method, information like qualifiers
def get_some_basebitmap():
bmp = c4d.bitmaps.BaseBitmap()
bmp.InitWith('C:/Users/niklas/Desktop/foo.png')
return bmp
class Dialog(GeDialog):
def CreateLayout(self):
AddIconButton(self, 1000, "Button One", c4d.COLOR_SYNTAX_STRING)
AddIconButton(self, 1001, "Button Two", c4d.Vector(1.0, 0.66, 0.12), IconButton.M_ICONRIGHT)
@NiklasRosenstein
NiklasRosenstein / add-mesh-points.py
Last active November 14, 2017 19:07
Script to insert points at the start or end of a mesh. Press enter to apply, escape to cancel.
# Copyright (c) 2013, Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@NiklasRosenstein
NiklasRosenstein / find-hierarchy-path.py
Last active November 14, 2017 19:07
Cinema 4D Python script. This script demonstrates how to find the hierarchy-path from one object to another using recursion.
# Copyright (c) 2013, Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@NiklasRosenstein
NiklasRosenstein / c4dpytask-1.py
Created September 15, 2013 13:13
#c4dpytask #beginner How can you position the selected objects at the world origin?
# @rosensteinn #c4dpytask
#
# How can you position the selected objects at the world origin?
import c4d
def main():
# Retrieve a list of all selected objects in the scene
# and iterate over them.
objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
@NiklasRosenstein
NiklasRosenstein / c4dpytask-2.py
Last active April 13, 2018 13:47
#c4dpytask #medium How can you load a texture and assign it to a plane with image dimensions? (you need a LoadDialog, BaseBitmap and Oplane)
# @rosensteinn #c4dpytask #medium How can you load a texture and assign
# it to a plane with image dimensions? (you need a LoadDialog, BaseBitmap
# and Oplane)
import c4d
def main():
# Poll the user for a filename. We specify that the file-type may be
# an image only.
filename = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_IMAGES)
@NiklasRosenstein
NiklasRosenstein / c4dpytask-3.py
Created September 19, 2013 12:47
@rosensteinn #c4dpytask Remove all empty texture tags on the Scene? Share it if you have a solution!
# @rosensteinn #c4dpytask Remove all empty texture tags on the Scene?
# Share it if you have a solution!
import c4d
def iter_hierarchy(op):
# Iterate over each tag of the current object.
for tag in op.GetTags():
# Check if the tag is a texture tag, and if it is, if it has
import c4d
def main():
# Retrieve the document settings.
bc = doc.GetSettingsInstance(c4d.DOCUMENTSETTINGS_DOCUMENT)
# Retrieve the current bitmask for the states of the selection filters.
flags = bc.GetLong(c4d.DOCUMENT_SELECTIONFILTER)
@NiklasRosenstein
NiklasRosenstein / c4dpytask-4.py
Created September 29, 2013 16:41
@rosensteinn #c4dpytask #beginner How can you apply a Cinema 4D command to each selected object individually?
# @rosensteinn #c4dpytask #beginner How can you apply a Cinema 4D
# command to each selected object individually?
import c4d
# The ID of the Command which should be executed for each object.
# In this case, I chose the "Group Objects" command.
COMMAND_ID = 100004772
def main():
@NiklasRosenstein
NiklasRosenstein / recover-scene.py
Last active March 20, 2022 06:12
This script imports a Cinema 4D scenefile and disables all deformers, generators and expressions. This is useful if the scene was saved at a state it is unrecoverable because of an issue while scripting (eg. saved the scene before a Python tag was executed, but now that Python tag always runs in an # infinite loop).
# Copyright (c) 2013, Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in