This was a fun little friday experiment. Transfering MoGraph data to Spline Data with Python Tag. I don’t know how useful it is, but it is fun to play with.

import c4d
from c4d import utils as u
from c4d.modules import mograph as mo

def main():
    clamp = op[c4d.ID_USERDATA,2] # User Data: 'Clamp'
    intrp = op[c4d.ID_USERDATA,3] # User Data: 'Interpolation'
    obj = op.GetObject() # Get object
    md = mo.GeGetMoData(obj) # Get MoData
    if md is None: return False # If there is no MoData, stop processing
    cnt = md.GetCount() # Get clone count
    marr = md.GetArray(c4d.MODATA_MATRIX) # Get MoData matrix
    spline = c4d.SplineData() # Initialize Spline Data
    for i in range(0, cnt):
        x = u.RangeMap(marr[i].off.x, 0, 100, 0, 1, clamp) # Calculate X position
        y = u.RangeMap(marr[i].off.y, 0, 100, 0, 1, clamp) # Calculate Y position
        spline.InsertKnot(x, y) # Insert new knot
        leftTangent = c4d.Vector(0, 0, 0) # Left tangent values
        rightTangent = c4d.Vector(0, 0, 0) # Right tangent values
        spline.SetKnot(i, c4d.Vector(x,y,0), 0, False, leftTangent, rightTangent, intrp) # Edit knot
    spline.DeleteKnot(spline.GetKnotCount()-1) # Remove some leftovers
    spline.DeleteKnot(spline.GetKnotCount()-1) # Yes, do it twice
    op[c4d.ID_USERDATA,1] = spline # Set spline data to user data

mograph_to_splinedata.c4d

Cinema 4D, Experimental, MoGraph, Python, Tag