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

    GetRad() / GetMp() update issue

    Cinema 4D SDK
    windows python 2025
    2
    2
    27
    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.
    • D
      datamilch
      last edited by

      Hi there,

      I have a python generator that reads the rad and mp of a clone of an object.
      When I move and transform the object the origin matrix of the clone is reset to 0.
      I was hoping to get the new rad and mp of the transformed state, but still get the same values as the original object.
      In the documentation it states, that "the radius is internally cached".
      So I suspect resetting the matrix will will not update the cache.
      Is it somehow possible to update this cache or do i have to calculate the bunding box myself?

      Best, Sebastian

      import c4d
      
      doc: c4d.documents.BaseDocument # The document the object `op` is contained in.
      op: c4d.BaseObject # The Python generator object holding this code.
      hh: "PyCapsule" # A HierarchyHelp object, only defined when main is executed.
      
      
      # ===============
      
      
      def csto( obj: c4d.BaseObject, doc = None ) -> c4d.BaseObject:
          """modeling command - current state to object
          """
          if not doc:
              doc = c4d.documents.GetActiveDocument()
          res = c4d.utils.SendModelingCommand( c4d.MCOMMAND_CURRENTSTATETOOBJECT, [ obj ], doc=doc)
          if not res: print ( f"main command: csto error: {obj.GetName()}" )
          else:
              res = res[0]
              for i in range(10):
                  if res.GetType()==c4d.Onull and res.GetDown():
                      res = res.GetDown().GetClone()
                  elif res.GetType()!=c4d.Onull:
                      res = res.GetClone()
                      break
                  else:
                      res = None
                      print ( f"main command: csto error 2: {obj.GetName()}" )
                      break
          return res
      
      
      def change_object_origin_matrix( obj: c4d.PointObject, matrix ):
          mg_old  = obj.GetMg()
          mg_new  = matrix
          m_delta = c4d.Matrix(~mg_old * mg_new )
          obj.SetAllPoints( [(p * ~m_delta) for p in obj.GetAllPoints()] )
          obj.SetMg( mg_new )
          return
      
      
      # ===============
      
      
      def main() -> c4d.BaseObject:
          """Called by Cinema 4D to retrieve the cache of the Python Generator object.
          """
          obj = op[c4d.ID_USERDATA,1]
          if obj:
              obj = obj.GetClone()
              obj = csto( obj )
              change_object_origin_matrix( obj, c4d.Matrix() )
              
              rad = obj.GetRad()
              mp = obj.GetMp()
              
              cube = c4d.BaseObject(c4d.Ocube)
              cube[c4d.PRIM_CUBE_LEN] = rad*2
              cube[c4d.ID_BASEOBJECT_REL_POSITION] = mp
      
              return cube
          
          else:
              return c4d.BaseObject(c4d.Onull)
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @datamilch
        last edited by ferdinand

        Hey @datamilch,

        Thank you for reaching out to us. GetRad and GetMp express the locally aligned bounding box of an object. I.e., the bounding box in the coordinate system of the object. For a world space aligned bounding box we once had this thread, the Cinema API does not offer this out of the box.

        So, transforming an object will never change its bounding box. What will change the bounding box of an object, is changing its size or changing the parameters of a generator object. When you change the parameters of a generator or when your instantiate a new object, you will have to execute the passes (BaseDocument.ExecutePasses) on a document that contains the object to see the correct bounding box - or wait for the next scene update.

        PS: Your script is also running illegal code. You cannot modify the active document off-main-thread. I assume the is a script for a Python generator object. Its main function runs off-main-thread and you call there your csto which in turn calls SendModelingCommand on the active document. This will all sooner or later crash.

        https://developers.maxon.net/docs/py/2025_3_1/manuals/manual_threading.html#threading-information

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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