Solved How to create object polygon from spline in C++?

Hello everyone.
I have a question that I want to create object solid from spline.
Can you show code C++ or Python ?.
Thanks you very much.


welcome to the forum. I am afraid this is not how things are working here. Your question is rather vague and also of such complexity that probably neither the SDK team nor forum members are willing to do the work for you. Some pointers.

  1. Creating a polygon object from a spline is a rather vague description. It could either mean performing a sweep operation along a spline or constructing a surface over a spline.
  2. Cinema has a sweep operator (the Sweep Object) you could use it programmatically. If you do not want to do that for some reason, you will have to segment both the sweep profile and the sweep curve into a set of points, then construct a series of frames (axis) over the sweep curve (for example via parallel transport) and then copy your profile point set to each frame and then triangulate the whole thing.
  3. If you want to construct a surface over a single spline (create a cap) you are pretty much on your own, since Cinema only recently got better tools in this department and they are AFAIK neither being in exposed the C++ nor Python SDK. The principal steps would be:
    a. Segmentize the input spline into a set of points.
    b. This is the hard one: Find a a surface approximation for the generated point set and generate additional points in the projected plane of that surface via for example a poisson distribution.
    c. Triangulate your extended point set (via a delauny triangulation for example, the C++ SDK offers a type for that)
    d. Point b becomes trivial when your spline is planar, i.e. all points of it lie in a plane, but that is not the case for all splines in your screenshot.


MAXON SDK Specialist

Hello and welcome,

before posting, please make sure you are familiar with this forum's rules and procedures: How to Post Questions

What kind of plugin do you want to write? A simple script, a tool or a generator? Are you familiar of the basic concepts of Cinema 4D? Do you have any previous coding experience?

For simplicity's sake I will present some Python code in form of a Python Script. The concepts can be transferred to C++ as well.

A polyon object is created by creating an instance of the PolygonObject class. This instance can be modified and then inserted in to the document.

import c4d

def main():
    # create polygon object
    numberOfPoints = 4
    numberOfPolygons = 1
    polyObject = c4d.PolygonObject(numberOfPoints, numberOfPolygons)
    if polyObject is None:
        raise RuntimeError("Could not create PolygonObject.")
    # set points
    points = []
    # set polygons  
    polygon = c4d.CPolygon(0,1,2,3)
    polyObject.SetPolygon(0, polygon)
    # insert object into document
    doc.InsertObject(polyObject, None, None)
    # update C4D

if __name__=='__main__':

Similarly, a spline is represented as a SplineObject. You can use the SplineHelp class to access positions along the spline:

import c4d

def main():
    # access active object
    if op is None:
        raise RuntimeError("No object selected")
    # check if active object is a spline object
    if op.GetType() != c4d.Ospline:
        raise RuntimeError("Object is no spline object")
    # init SplineHelp
    splineHelp  = c4d.utils.SplineHelp()
    res = splineHelp.InitSpline(op)
    if res == False:
        raise RuntimeError("Could not init SplineHelp.")
    # Sample positions along the spline
    for i in xrange(20):
        offset = i * .05
        pos = splineHelp.GetPosition(offset, 0)

if __name__=='__main__':

With that information you can build your poylgons.

You find more complex examples how to create poylgon objects in various generator plugins:

best wishes,

Thanks everyone.

The purpose of me is export model from revit to cinema 4d.
I choose other way.
Thanks you very much.