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

    Create BaseBitmap() from Text?

    Cinema 4D SDK
    r21 python
    2
    5
    505
    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.
    • B
      bentraje
      last edited by

      Hi,

      Is it possible to create bitmap from text?
      Currently, I use separate thumbnail/image files to be use as bitmap but they are relatively simple
      that perhaps I can do them at run time in C4D.

      You can see what I am after in this image:
      https://www.dropbox.com/s/a2saczuy5ah5jnf/c4d208_create_text_as_bitmap.jpg?dl=0

      The use case for this is a toggle button for HIDE/UNHIDE visibility control. The Green means hide and the Red means unhide. I already have the toggle functionality implemented, its only the BaseBitmap() from Text portion.

      Thank you

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

        Hi @bentraje

        this can be achieved with the c4d.bitmaps.GeClipMap and GeClipMap.TextAt.
        There is an example of GeClipMap in geclipmap_fill_color_bitmap_r18.py.

        Or you can Create a GeUserArea that will display your BaseBitmap GeUserArea.DrawBitmap and then call GeUserArea.DrawText
        The use of GeUserArea is preferred since it's faster than using a GeClipMap. But you can't retrieve a BaseBitmap from your GeUserArea drawing result, so it's up to you do decide which one fits the best for your use case.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • B
          bentraje
          last edited by

          @m_adam

          Thanks for the response. I was able to draw a text with a colored background.
          Just hit a snag on this portion.
          GeClipMap.SetFont(font_description, font_size)

          I'm assuming the font description is the font name and font type.
          How do I set it to Segoe UI with Bold style?

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

            This is a bit tricky since Font are not so well organized.

            So the best way I found is

            def GetSegoeUiBoldFont():
                bcFonts = c4d.bitmaps.GeClipMap.EnumerateFonts(c4d.GE_CM_FONTSORT_HIERARCHICAL)
                for familyId, familyBc  in bcFonts:
                    for fontDescriptionId, fontDescription in familyBc:
                        if fontDescription[508] == "SegoeUI-Bold":
                            return fontDescription
            

            And if you want another font, simply print the content of fontDescription and see which one may fit the best for you.

            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 1
            • B
              bentraje
              last edited by

              @m_adam

              Thanks for the response. For some reason, the return value is not accepted by the SetFont. It does not error out. It just uses the default font.

              In addition, how were you able to determine that the [508] is for the font name? I can't seem to see such reference in the documentation.

              You can check the working code here:

              import c4d
              from c4d import gui
              # Welcome to the world of Python
              
              
              
              def GetSegoeUiBoldFont():
                  bcFonts = c4d.bitmaps.GeClipMap.EnumerateFonts(c4d.GE_CM_FONTSORT_HIERARCHICAL)
                  for familyId, familyBc  in bcFonts:
                      for fontDescriptionId, fontDescription in familyBc:
                          if fontDescription[508] == "SegoeUI-Bold":
                              return fontDescription
                              print fontDescription
              
              def main():
                  w = 50
                  h = 50
                  image_with_text = c4d.bitmaps.GeClipMap()
                  image_with_text.Init(w=w,h=h,bits=32)
              
                  image_with_text.BeginDraw()
              
                  image_with_text.SetColor(125,255,255)
                  image_with_text.FillRect(x1=0,y1=0,x2=50,y2=50)
              
                  image_with_text.SetColor(0,0,0)
                  font_bc = GetSegoeUiBoldFont()
                  print font_bc
                  font_size = 15
                  image_with_text.SetFont(font_bc,font_size)
                  image_with_text.TextAt(x=10,y=15,txt='head')
              
                  image_with_text.EndDraw()
                  bmp = image_with_text.GetBitmap()
                  c4d.bitmaps.ShowBitmap(bmp)
              
              
              # Execute main()
              if __name__=='__main__':
                  main()
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post