Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Setting the FontData for a Text Object

    Cinema 4D SDK
    s22 python sdk
    1
    2
    282
    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.
    • ?
      A Former User
      last edited by A Former User

      Hello,
      I am trying to set the Font for a Text Objectt.

      I've been following the code from this forum topic: SetFont not working

      This example uses MoText, however, and I would like to use the Text Object. I'm unable to access its FontData via PRIM_TEXT_FONT:

      import c4d
      
      def main(doc):
          textObject = c4d.BaseObject(c4d.Osplinetext)
          doc.InsertObject(textObject)
          print textObject[c4d.PRIM_TEXT_FONT]
          #prints None
          c4d.EventAdd()
      
      if __name__=='__main__':
          main(doc)
      

      If I change the Font manually and then print Text[c4d.PRIM_TEXT_FONT] from the Command Line it does print the Font Data, but I don't know how to change this Font in Python.

      Can anyone explain how to get/set the FontData with a Text Object? Thank you!

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User
        last edited by A Former User

        For whatever reason, the default Text Object has no FontData in Text[c4d.PRIM_TEXT_FONT]. By creating a FontData instance, I was able to set the Font.

        import c4d
        
        def main(doc):
            textObject = c4d.BaseObject(c4d.Osplinetext)
            doc.InsertObject(textObject)
        
            fontData = c4d.FontData()
            
            bc = c4d.BaseContainer()
            bc.SetString(500, 'Arial')
            bc.SetString(501, '11')
            bc.SetInt32(502, 400)
            bc.SetInt32(503, 0)
            bc.SetString(509, 'Arial')
            bc.SetString(508, 'ArialMT')
            fontData.SetFont(bc)
            
            textObject[c4d.PRIM_TEXT_FONT] = fontData
            textObject[c4d.ID_BASELIST_NAME] = bc[500]
            textObject[c4d.PRIM_TEXT_TEXT] = bc[500]
            c4d.EventAdd()
        
        if __name__=='__main__':
            main(doc)
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post