One thing you will do over and over again in scripting Cinema 4D is to go through your scene. Usually you go hunting for certain objects, tags or materials.
This is pretty straight forward using the BaseList2D class methods by
using GetNext() and GetDown() but can get old pretty fast as you
are doing the same checking and safeguards over and over again.
Python - like many modern programming languages - has a neat iterator pattern that is ingrained into the language. So instead of using Cinema 4D’s object model you can do it more comfortably by using Python in a more natural way.
Now that we have had a short glimpse on the basics in the first article lets move on to do something meaningful. So far it has been a purely academic discourse.
Usually, we want a script to do something with the objects we have in a scene. So the first step is to look at how we can access the scene file and go through selected objects and perform Cinema 4D commands on them.
The Python integration into Cinema 4D is quite thorough. There are several places where you can use Python to script and Python is integrated as a first class citizen with the same level of access like Cinema 4D’s internal scripting language COFFEE as well as the C++ API.
There are different places in which you can use Python:
As you can see, there are plenty of options to use Python in Cinema 4D. For a start let us focus on using a Python script - ignoring the other possibilities for now.
I think it is pretty safe to say that Python has become the mostly widely adopted scripting language across many, many CG and VFX applications. A few years back almost every tool had its very own choice of scripting language. They pretty much still exist and from pure history they are still heavily used for existing tools or just for the fact that developers, TDs and artists rely on them because they know them well. Python increasingly replaces them across the board though.
For a guy that has a background in software development and CG/post production the ever wonderful world of production craft and equipment can be full of small technical hurdles. Sometimes it takes a moment or two to make sense of what others have honed for decades.
When looking into matte boxes and filters one of that “what?!” moments was when I looked at ND (neutral density) filters. Wading through filter stages and form factors like 4x4 and 4x5.65, graduated and what not it took me a while to make sense of their rating. Assuming that a 0.3 filter would let through 30% of the light was quickly ridiculed by filters with a factor of 1.2 or higher. So the guess of a multiplication factor was ruled out quickly.