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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Getting radius of text during rendering

    Cinema 4D SDK
    2024 python
    2
    2
    375
    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.
    • G
      gsmetzer
      last edited by

      I am able to get the bounding box of text with .GetRad() and it works nicely in the viewport. However, when I render my radius goes to zero. I created a simple scene to show the problem. Rad_NotUpdatingRender_01.c4d Is there any hacks to get the radius working in render?

      In a python Generator

      import c4d
      
      
      #I'm trying to get the bounding box of each text object working in the renderer
      #The viewport works fine, but when I render the 'widths' list goes to [0,0]
      
      children = op.GetChildren()
      
      widths = []
      #loop through children  (text objects)
      for i in range(len(children)):
          
          #get the radius of each child
          radius = children[i].GetRad()
          #bbox = c4d.utils.GetBBox(children[i], children[i].GetMg())[0].x
          
          #build list of widths.
          widths.append(round(radius.x))
      
      print(widths)
      
      def main():
          #send width list to another object to see in the render
          op[c4d.ID_USERDATA,1][c4d.PRIM_TEXT_TEXT] = str(widths)
      
          return
      
      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @gsmetzer
        last edited by

        Hi @gsmetzer ,

        Thank you for providing the scene that shows the problem!

        Your code in the Python generator should be scoped with functions and classes. The code outside of main() function is only run once. Please also make sure you're familiar with cinema threading restrictions: Threading Manual.

        Once you cover the code into a separate function it starts working (check the code below). Although, you are kind of misusing the python generator object (as it doesn't generate any cache). The Python Tag could probably be a better fit here.

        Another note is that although changing other object's attributes is somewhat acceptable, you can still fall into a trap of changes being delayed, because of lacking the recalculate pass after you've changed the value. It might be worth trying to store your text in a user data attribute of python generator. And for the text object just create an xpresso tag that drives the text value from the string in the user data attribute of python generator. This way you can fine tune the execution priority order: documentation.

        One more thing. I've also received the missing font error upon loading your test scene, make sure it is fixed to have the code working.

        Cheers,
        Ilia

        Code for your python generator:

        import c4d
        
        def foo():
            children = op.GetChildren()
        
            widths = []
            for i in range(len(children)):
                radius = children[i].GetRad()
                widths.append(round(radius.x))
        
            return widths
        
        def main():
            op[c4d.ID_USERDATA,1][c4d.PRIM_TEXT_TEXT] = str(foo())
            return
        

        MAXON SDK Specialist
        developers.maxon.net

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