Tips to switch from C.O.F.F.E.E to PythonΒΆ

Tips to switch from C.O.F.F.E.E to Python

As you may know, R20 drop the support of C.O.F.F.E.E, read The End of C.O.F.F.E.E for more information.
Even if our role is not to teach you python, we can at least help you to convert C.O.F.F.E.E script to Python by giving you some tips.
First of all, you can find some valuable python resource to learn in the following blog post Public Resources for Cinema 4D Plugin Development in Python.

This list is not exhaustive and if you find any difficulties you can contact us in the forum or even by mail: [email protected].

C.O.F.F.E.E

Python


GetPrev
GetPred

Math functions Math functions

In python there is no math class from c4d module. But you can found corresponding functions in standard python math module or in c4d.utils module


Cos Sin
println (cos(75));
println (sin(50));
Cos Sin

There is multiples way to get Sin Con in Python.
First, using the c4d modules get both at once.

# Get Both at once
sin, cos = c4d.utils.SinCos(90)
print sin, cos
You can also generate lambda helper
cos = lambda x: c4d.utils.SinCos(x)[1]
sin = lambda x: c4d.utils.SinCos(x)[0]
     
print cos(75)
print sin(50)
Finally, you can use the standard python math module

#Using math module
import math

print math.cos(75)
print math.sin(50)

exp example
println(exp(10));
exp example
import math
print math.exp(10)

MinimizeAngle
var v1 = vector(50, 20, 30);
var v2 = vector(-400, 20, 30);
println(MinimizeAngle(v1, v2));
GetOptimalAngle

In python, MinimizeAngle is renamed by GetOptimalAngle

v1 = c4d.Vector(50, 20, 30)
v2 = c4d.Vector(-400, 20, 30)
print c4d.utils.GetOptimalAngle(v1, v2, c4d.ROTATIONORDER_DEFAULT)

Matrix Acces

GetV0, GetV1, GetV2, GetV3

var m = op->GetMg();
var pos = m->GetV0();
var xAxis = m->GetV1();
var yAxis = m->GetV2();
var zAxis = m->GetV3();
     
println(pos, xAxis, yAxis, zAxis);
Matrix Acces

I also suggest to read Matrix Fundamentals off, v1, v2, v3

m = op.GetMg()
pos = m.off
xAxis = m.v1
yAxis = m.v2
zAxis = m.v3
 
print pos, xAxis, yAxis, zAxis

GetHPB
var m = op->GetMg();
var hpbRot = m->GetHBP();
 
println(hpbRot);
MatrixToHPB
m = op.GetMg()
hpbRot = c4d.utils.MatrixToHPB(m)
 
print hpbRot

Noise class

Turbulence example

var noise = new(Noise);
var jitter = 10;
var x = 20;
var y = 30;
var z = 40;
var absolute= FALSE;
 
println(noise->Turbulence(jitter, absolute, x ,y, z));
C4DNoise Class

Turbulence example

noise = c4d.utils.noise.C4DNoise()
jitter = 10
x = 20
y = 30
z = 40
absolute= False
     
print(noise.Turbulence(c4d.Vector(x, y, z), jitter, absolute))

Random class
var r = new(Random);
r->Init(8374946);
 
println(r->Get01());
println(r->Get11());
println(r->GetG01());
println(r->GetG11());
Random class

In python, there is no Random class from c4d module, but you can find the corresponding function in standard python random module.
Then keep in mind even using the same seed.
Results will be different from C.O.F.F.E.E to Python.

import random
r.seed(8374946)
 
print random.uniform(0, 1) # Equals to Get01
print random.uniform(-1, 1)  # Equals to Get11
print random.gauss(0.5, 0.09) # Equals to GetG01
print random.gauss(0.0, 0.18) # Equals to GetG11