Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Dear c4d fellows, I've started to develop a plugin for c4d. Suppose a user drew some spline and made it an active object. I want to read out spline data (bezier coordinates and the rest).
Somehow, in debugging mode I don't see any data. I use:
BaseObject* spline = document->GetActiveObject();
But then I see in visual studio, that it created a pointer "spline" but that's it. The only thing I see is that under my variable spline BaseList2D, GeListNode, C4DAtomGoal and C4DAtom are all empty.!
So how does one achieve this?
Yaroslav.
Actually, I would use static_cast<SplineObject*>(op) instead of ToSpline(op) which is defined as only (SplineObject*)(op). After the appropriate tests (op->GetInfo() & OBJECT_ISSPLINE, op->IsInstanceOf(Ospline), et cetera), of course.
static_cast<SplineObject*>(op)
ToSpline(op)
(SplineObject*)(op)
op->GetInfo() & OBJECT_ISSPLINE
op->IsInstanceOf(Ospline)
You have to cast the BaseObject into a SplineObject - if the object is actually a SplineObject or a spline generator.
You find some example code here: https://developers.maxon.net/docs/Cinema4DCPPSDK/html/page_manual_baseobject.html#page_manual_baseobject_flags
Then you can use the SplineObject / PointObject class as usual.
Understood! Thank you, PluginStudent and fwilleke80 so much! Both of your answers helped me!
I have now the follow-up question. Forgive me the lack of my expertise. Here is my code which retrieves the spline drawn by the user.
BaseDocument* const document = GetActiveDocument(); SplineObject* spline = nullptr; BaseObject* object = document->GetActiveObject(); if (object->IsInstanceOf(Ospline)) spline = ToSpline(object);
Now the question. Suppose the curve is the combination of bezier and linear elements (they are joint). How do we retrieve
I've looked through SplineObject and PointObject classes.
The only methods that I found are:
const Vector* vec = (*spline).GetPointR();
which is the coordinate of the first point only. But what about the next point?
From SplineObject I found the method GetSplinePoint(t, segment). If I write
Vector vec1 = (*spline).GetSplinePoint(1, 0);
I retrieve the coordinate of the last point of the whole curve (i.e. the end point of the last element). Do you know how to retrieve the rest of the points?
@Yaroslav said in Get Spline Data from document->GetActiveObject();:
Forgive me the lack of my expertise.
Hey, we were all beginners at some point. I still ask stupid questions
Now the question. Suppose the curve is the combination of bezier and linear elements (they are joint).
Not sure what you mean here. A spline can only be of one type. SPLINETYPE::LINEAR or SPLINETYPE::BEZIER or one of the other types.
SPLINETYPE::LINEAR
SPLINETYPE::BEZIER
See https://developers.maxon.net/docs/Cinema4DCPPSDK/html/group___s_p_l_i_n_e_t_y_p_e.html#ga7ac05237453839e3b099f55f27512115
I guess you mean that some of the spline's points have tangents, and other's don't (meaning they also have tangents, but with zero length)?
How do we retrieve all the start and end points of the constituent elements?
How do we retrieve
const Vector* padr = splineObject->GetPointR(); // Read-only or Vector* padr = splineObject->GetPointW(); // Writeable
const Vector* padr = splineObject->GetPointR(); // Read-only
Vector* padr = splineObject->GetPointW(); // Writeable
See https://developers.maxon.net/docs/Cinema4DCPPSDK/html/class_sculpt_object.html#a5f6babccd3d9b408be7f3756fe5767a5
the control points of Bezier curved elements?
const Tangent* tangents = splineObject->GetTangentR(); // Read-only or Tangent* tangents = splineObject->GetTangentW(); // Writeable
const Tangent* tangents = splineObject->GetTangentR(); // Read-only
Tangent* tangents = splineObject->GetTangentW(); // Writeable
See https://developers.maxon.net/docs/Cinema4DCPPSDK/html/class_spline_object.html#ab9d27c0ef7b361e532da250c595fe9d2
The only methods that I found are: const Vector* vec = (*spline).GetPointR(); ...
This is correct. There are as many points as splineObject->GetPointCount() tells you.
splineObject->GetPointCount()
To get the position of a spline point, use:
// Get const array of points const Vector *points = splineObject->GetPointR(); // Get a specific point from the array const Vector pointPos = points[123];
Same applies to the tangents.
// Get writeable array of tangents Tangents* tangents = splineObject->GetTangentW(); // Change a tangent tangents[123].vl = Vector(some, nice, direction); tangents[123].vr = Vector(another, nice, direction); tangents[123] = myTangent;
You might want to take a look into circle.cpp from the cinema4dsdk project.
circle.cpp
cinema4dsdk
Cheers, Frank
Dear Frank, Thanks for the comprehensive reply! Everything works just as expected! It is such a scientific joy to explore the cog wheels of the wander-box called cinema4D.
hi,
thanks a lot @fwilleke80 and @PluginStudent for the answer
I just want to add that you can also use SplineHelp in some cases to retrieve the informations you need from a spline.
Cheers, Manuel
@m_magalhaes
Thank you, Manuel!