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

    Store SplineData inside a Container

    Cinema 4D SDK
    python
    2
    3
    397
    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.
    • R
      rui_mac
      last edited by

      Is is possible to store a SplineData object inside a Container?
      Or must I store all the data points as vector data inside a subcontainer?

      1 Reply Last reply Reply Quote 0
      • R
        rui_mac
        last edited by

        Ok, fixed it, using InsData.

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @rui_mac
          last edited by ferdinand

          Hey @rui_mac,

          thank you for reaching out to us. It is great to hear that you solved your problem yourself. I would however recommend to use BaseContainer.SetData.

          As a brief explanation, because the Python docs are not too clear on what can be written with SetData, and not all users/readers might be familiar with the C++ API. The SetData and GetData methods in C++ allow you to write anything that can be expressed as GeData into a BaseContainer. That type is not exposed in Python. When looking at the GeData documenation in C++, we can see that there is the constructor GeData (Int32 type, const CustomDataType &data), i.e., CustomDataType can be wrapped as GeData, i.e., SplineData can be written into a BaseContainer. Because this also comes up from time to time, you should be aware that the data is being copied. See example at the end of my posting for details.

          Cheers,
          Ferdinand

          """Demonstrates how to write SplineData into a BaseContainer.
          """
          
          import c4d
          
          def UnpackData(bc: c4d.BaseContainer, cid: int) -> None:
              """
              """
              data: any = bc.GetData(cid)
              if not isinstance(data, c4d.SplineData):
                  return
          
              print("\nThe first two knots of the spline in the container:")
              for i, knot in enumerate(data.GetKnots()[:2]):
                  print (i, knot)
          
          def main() -> None:
              """
              """
              # Create a spline data instance and use MakeCubicSpline() to generate some data in it.
              spline: c4d.SplineData = c4d.SplineData()
              spline.MakeCubicSpline(lPoints=4)
          
              # Iterate over the knots.
              print("The first two knots of the original spline:")
              for i, knot in enumerate(spline.GetKnots()[:2]):
                  print (i, knot)
          
              # Store the SplineData in a BaseContainer. The data will be copied, so any modification made
              # to #spline after inserting it, will not be reflected.
              print ("\nWriting spline into container.")
              bc: c4d.BaseContainer = c4d.BaseContainer()
              bc.SetData(1000, spline)
          
              # Modify the first knot of the spline.
              spline.SetKnot(0, c4d.Vector(1), c4d.FLAG_KNOT_T_BREAK)
          
              print("\nThe first two knots of the modified spline:")
              for i, knot in enumerate(spline.GetKnots()[:2]):
                  print (i, knot)
          
              UnpackData(bc, 1000)
          
          if __name__ == '__main__':
              main()
          

          MAXON SDK Specialist
          developers.maxon.net

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