Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get Spline Data from document->GetActiveObject();

    Cinema 4D SDK
    c++
    4
    8
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      Yaroslav
      last edited by Manuel

      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.

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        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.

        1 Reply Last reply Reply Quote 1
        • fwilleke80F
          fwilleke80
          last edited by fwilleke80

          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.

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 1
          • Y
            Yaroslav
            last edited by Yaroslav

            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

            1. all the start and end points of the constituent elements?
            2. 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 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.

            fwilleke80F 1 Reply Last reply Reply Quote 0
            • fwilleke80F
              fwilleke80 @Yaroslav
              last edited by fwilleke80

              @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.

              See https://developers.maxon.net/docs/cpp/2023_2/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

              1. all the start and end points of the constituent elements?

              const Vector* padr = splineObject->GetPointR(); // Read-only
              or
              Vector* padr = splineObject->GetPointW(); // Writeable

              See https://developers.maxon.net/docs/cpp/2023_2/class_sculpt_object.html#a5f6babccd3d9b408be7f3756fe5767a5

              1. the control points of Bezier curved elements?

              const Tangent* tangents = splineObject->GetTangentR(); // Read-only
              or
              Tangent* tangents = splineObject->GetTangentW(); // Writeable

              See https://developers.maxon.net/docs/cpp/2023_2/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.

              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.

              Cheers,
              Frank

              www.frankwilleke.de
              Only asking personal code questions here.

              1 Reply Last reply Reply Quote 0
              • Y
                Yaroslav
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • ManuelM
                  Manuel
                  last edited by

                  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

                  MAXON SDK Specialist

                  MAXON Registered Developer

                  Y 1 Reply Last reply Reply Quote 0
                  • Y
                    Yaroslav @Manuel
                    last edited by

                    @m_magalhaes

                    Thank you, Manuel!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post