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

    [python] SetFont not working

    Cinema 4D SDK
    r20 sdk python
    2
    6
    1.3k
    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.
    • I
      iluxa7k
      last edited by r_gigante

      Hello
      C4D version: 20.059
      OS: Windows 10

      I select motext and try to change font(fontdata) for text by script

      import c4d
      from c4d import plugins
      def main() :
        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')
        # select mograph text
        op[c4d.PRIM_TEXT_FONT].SetFont(bc)
        op.Message(c4d.MSG_CHANGE)
        c4d.EventAdd()
      if __name__=='__main__':
        main()
      

      can not get it work ☹

      1 Reply Last reply Reply Quote 0
      • I
        iluxa7k
        last edited by

        Found such solution:

        import c4d
        
        def main():
        
            bc = c4d.BaseContainer()
            ids = c4d.PRIM_TEXT_FONT
            #ids = c4d.DescID(c4d.DescLevel(2117,1009372,5178))
            op.SetParameter(ids, bc, c4d.DESCFLAGS_SET_0)
            bc.SetString(500, 'Arial')
            bc.SetString(501, '11')
            bc.SetInt32(502, 400)
            bc.SetInt32(503, 0)
            bc.SetString(509, 'Arial')
            bc.SetString(508, 'ArialMT')
            new_fd = c4d.FontData()
            new_fd.SetFont(bc)
            op.SetParameter(ids, new_fd, c4d.DESCFLAGS_SET_0)    
            c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE))
            c4d.gui.GeUpdateUI()
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          The issue you figured out is pretty common in python. So actually when you do op[c4d.PRIM_TEXT_FONT] (aka GetParameter) you retrieve a copy of this CustomDataType. That means if you want to modify something it will not be reflected in the UI.

          Finally, you don't need all the update code only a c4d.EventAdd is enough.

          import c4d
          
          def main():
              # Retrieves a copy of the actual FontData
              fontData = op[c4d.PRIM_TEXT_FONT]
              
              # Defines parameters for this 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)
              
              # Push back this FontData into the object
              op[c4d.PRIM_TEXT_FONT] = fontData
              
              # Pushes an update event to Cinema 4D
              c4d.EventAdd()
          
          # Execute main()
          if __name__=='__main__':
              main()
          

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • I
            iluxa7k
            last edited by

            Hello Maxime
            Thank you.
            I tried such form and can not get it work. I think i'm "messing"(replace FontData to BaseContainer) data for GUI, so it does not work for me.

            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by

              In which version are you? The code I posted is working nicely in R20.059.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              I 1 Reply Last reply Reply Quote 0
              • I
                iluxa7k @m_adam
                last edited by

                @m_adam said in [python] SetFont not working:

                In which version are you? The code I posted is working nicely in R20.059.

                20.059. Before i tried any methods, that's my fail. Not work for me. From new start of c4d. - it works

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