Get Spline Data from document->GetActiveObject();
-
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.
-
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/cpp/2023_2/page_manual_baseobject.html#page_manual_baseobject_flags
Then you can use the SplineObject / PointObject class as usual.
-
Actually, I would use
static_cast<SplineObject*>(op)
instead ofToSpline(op)
which is defined as only(SplineObject*)(op)
.
After the appropriate tests (op->GetInfo() & OBJECT_ISSPLINE
,op->IsInstanceOf(Ospline)
, et cetera), of course. -
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- all the start and end points of the constituent elements?
- the control points of Bezier curved elements?
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 writeVector 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.
-
@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
orSPLINETYPE::BEZIER
or one of the other types.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?
const Vector* padr = splineObject->GetPointR(); // Read-only
or
Vector* padr = splineObject->GetPointW(); // Writeable
- the control points of Bezier curved elements?
const Tangent* tangents = splineObject->GetTangentR(); // Read-only
or
Tangent* tangents = splineObject->GetTangentW(); // Writeable
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.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 thecinema4dsdk
project.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.Yaroslav.
-
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!