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

    BitmapButton not work

    Cinema 4D SDK
    2024 python
    2
    5
    761
    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.
    • chuanzhenC
      chuanzhen
      last edited by

      Hi,
      279910df-7a67-4c2e-8299-6d21dfd536f5-image.png
      I created a Bitmaobutton GUI, but the GUI only works in the right area of the image, and clicking on the left does not work。
      my code:

      custom_gui = self.AddCustomGui(ID, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_SCALEFIT, 0, 0, bc)
      custom_gui.SetImage(bitmap)
      

      Thanks for any help!

      相信我,可以的!

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @chuanzhen
        last edited by

        Hey @chuanzhen,

        Thank you for reaching out to us. Can you please provide an executable code example for your problem, i.e., a little dialog which creates your rig there. Please also provide the bitmap you load there. I have a hunch why this might happen, but I need your code and bitmap to confirm.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        chuanzhenC 1 Reply Last reply Reply Quote 0
        • chuanzhenC
          chuanzhen @ferdinand
          last edited by

          @ferdinand
          --video:

          --code:

          import c4d
          from c4d import gui
          # Welcome to the world of Python
          def LoadCustomIcon(input_v):
          
          
              bc_customgui = c4d.BaseContainer()
              bc_customgui.SetBool(c4d.BITMAPBUTTON_BUTTON, True)
              # bc_customgui.SetBool(c4d.BITMAPBUTTON_NOBORDERDRAW, False)
              bc_customgui.SetInt32(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_THIN_IN)
              bc_customgui.SetInt32(c4d.BITMAPBUTTON_OUTBORDER, c4d.BORDER_THIN_IN)
          
              
              bmp_dict = gui.GetIcon(input_v)
              icon_data = c4d.IconData()
              icon_data.bmp = bmp_dict['bmp']
              icon_data.x, icon_data.y, icon_data.w, icon_data.h = bmp_dict['x'], bmp_dict['y'], bmp_dict['w'], bmp_dict['h']
              bmp = icon_data.GetClonePart()
              
              return bmp, bc_customgui
          
          class test_dialog(gui.GeDialog):
              def CreateLayout(self):
                  # Other than edit fields, buttons do not have a builtin bubble help.
                  self.GroupBegin(1000,c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT,2,0)
                  self.AddButton(1001, c4d.BFH_SCALEFIT, name = "Foo")
                  
                  
                  
                  img, bc = LoadCustomIcon(431000053)
                  bc.SetString(c4d.BITMAPBUTTON_TOOLTIP, "<b>xxx")
                  custom_gui = self.AddCustomGui(1002, c4d.CUSTOMGUI_BITMAPBUTTON,"", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, 0, bc)
                  custom_gui.SetImage(img)
                  self.GroupEnd()
                  return True
              """def Message(self,msg,result):
                  msg_id = msg.GetId()
                  if msg_id == c4d.BFM_GETCURSORINFO:
                      result.SetId(c4d.BFM_GETCURSORINFO)
                      result.SetString(c4d.RESULT_BUBBLEHELP, "Show something")
                      return True
                  return c4d.gui.GeDialog.Message(self, msg, result)"""
              def Command(self, id, msg):
                  if id == 1002:
                      gui.MessageDialog("Click success!")
                      return True
                  return True
          
          
          # Execute main()
          if __name__=='__main__':
          
          
              dlg = test_dialog()
          
              dlg.Open(c4d.DLG_TYPE_ASYNC,0 -1,-1,400,400)
          

          相信我,可以的!

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @chuanzhen
            last edited by ferdinand

            Hello @chuanzhen,

            In short, I would say you are simply misusing bitmap buttons here. They are not meant to be used with BFH_SCALEFIT. My hunch was that BITMAPBUTTON_FORCE_SIZE will have an impact here and that turned out to be true, but will also align the image to the left in the button (the extrude icon button below is an example for that). In general, you must use BFH_FIT/BFV_FIT for bitmap buttons (sweep icon), as our bitmap buttons are not meant to hold text or be wider than the image that they display. You can add custom spacing between buttons with an extra group (sweep icon button).

            Cheers,
            Ferdinand

            Result

            63ff1930-1c2b-4585-b2a1-8cc22ac6fd0b-image.png

            Code

            """Demonstrates how to add bitmap buttons to a dialog with different layout options.
            """
            
            import c4d
                
            class TestDialog(c4d.gui.GeDialog):
                """
                """
                ID_GRP_MAIN: int = 1000
                ID_GROUP_SUB: int = 1001
            
                ID_BTN_1: int = 2000
                ID_BTN_2: int = 2001
                ID_BTN_3: int = 2002
                ID_BTN_4: int = 2003
            
                ID_ICON_1: int = 431000053
                ID_ICON_2: int = 5116
                ID_ICON_3: int = 5117
                ID_ICON_4: int = 5118
                
                def AddBitmapButton(self, gid: int, iid: int, flags: int, 
                                    forceSize: int = 0) -> c4d.gui.BitmapButtonCustomGui:
                    """Adds a bitmap button to the dialog with the given gadget ID, icon ID, flags, and optional
                    forced size.
                    """
                    bmp: c4d.bitmaps.BaseBitmap = c4d.bitmaps.InitResourceBitmap(iid)
                    if bmp is None:
                        raise ValueError(f"Failed to load the icon with the ID {iid}.")
                
                    bc: c4d.BaseContainer = c4d.BaseContainer()
                    bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True)
                    bc.SetInt32(c4d.BITMAPBUTTON_BACKCOLOR, c4d.COLOR_BGEDIT)
                    if forceSize:
                        bc.SetInt32(c4d.BITMAPBUTTON_FORCE_SIZE, forceSize)
            
                    gui: c4d.gui.BitmapButtonCustomGui = self.AddCustomGui(
                        gid, c4d.CUSTOMGUI_BITMAPBUTTON, "", flags, 0, 0, bc)
                    if not isinstance(gui, c4d.gui.BitmapButtonCustomGui):
                        raise ValueError("Failed to add the custom GUI.")
                    gui.SetImage(bmp)
            
                def CreateLayout(self) -> bool:
                    """Creates the layout of the dialog.
                    """
                    self.SetTitle("Test Dialog")
            
                    # Open an explicit outer group for the main layout. This group scales horizontally and
                    # vertically and has 4 columns.
                    self.GroupBegin(self.ID_GRP_MAIN, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=4)
            
                    # Add a bitmap button just like you did with BFH_SCALEFIT. This results in the "broken" left
                    # whitespace as a non-clickable area.
                    self.AddBitmapButton(self.ID_BTN_1, self.ID_ICON_1, c4d.BFH_SCALEFIT)
            
                    # Do the same but force the size of the button to 32x32 pixels, this will work, but the
                    # image will be left aligned.
                    self.AddBitmapButton(self.ID_BTN_2, self.ID_ICON_2, c4d.BFH_SCALEFIT, forceSize=32)
            
                    # This is how bitmap buttons are actually meant to be used, with BFH_FIT and BFV_FIT. Bitmap
                    # buttons are not meant to have white space to their left or right.
                    self.AddBitmapButton(self.ID_BTN_3, self.ID_ICON_3, c4d.BFH_FIT)
            
                    # When you want whitespace to the left and right of the button, you can use a group with
                    # BFH_SCALEFIT and add the button with BFH_SCALE | BFH_CENTER. This will add whitespace to 
                    # the left and right of the button.
                    self.GroupBegin(self.ID_GROUP_SUB, c4d.BFH_SCALEFIT, initw=100)
                    self.AddBitmapButton(self.ID_BTN_4, self.ID_ICON_4, c4d.BFH_SCALE | c4d.BFH_CENTER)
                    self.GroupEnd()
            
                    # An even easier way to add whitespace to the left and right of a button is to use the
                    # GroupSpace method to set the spacing between elements in a group. But with that you cannot
                    # control a single element individually.
                    # self.GroupSpace(10, 2)
            
                    self.GroupEnd()
            
                    return True
                
                def Command(self, cid: int, msg: int) -> bool:
                    """Handles the command messages.
                    """
                    if cid in (self.ID_BTN_1, self.ID_BTN_2, self.ID_BTN_3, self.ID_BTN_4):
                        c4d.gui.MessageDialog(f"Button {cid} clicked.")
                        return True
                    return True
            
            dlg: TestDialog = TestDialog()
            # Execute main()
            if __name__=='__main__':
                dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=200, defaulth=200)
            

            MAXON SDK Specialist
            developers.maxon.net

            chuanzhenC 1 Reply Last reply Reply Quote 1
            • chuanzhenC
              chuanzhen @ferdinand
              last edited by

              @ferdinand Thanks👍

              相信我,可以的!

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