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

    Simple Box Gui Creation

    Cinema 4D SDK
    python windows r19
    2
    9
    2.7k
    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 bentraje

      Hi,

      I'm trying to create a GUI tool that lets me change the display color at will. Since we are talking about colors, I would like to the "buttons" to be colors rather than just a plain text button "Change to Green". You cans see an example attached in this post.

      https://www.dropbox.com/s/j7k385dlx0obnb2/c4d070_UI_colorizer.JPG?dl=0

      I tried looking up in the GUI documentation but nothing seems to fit my description.

      Is there a way around this? Thank you for looking at my problem.

      1 Reply Last reply Reply Quote 0
      • a_blockA
        a_block
        last edited by

        Hi,

        may I ask you to please add tags to your post (see Read Before Posting)? For example I'm not sure, if you are looking for a C++ or Python solution.

        In general the BitmapButtonCustomGui (C++, Python) should do the trick for you.

        You can see the usage in our C++ examples:
        In a parameter description: objectdata_descriptions.cpp
        In a GeDialog: gedialog_gadgets.cpp

        Cheers,
        Andreas

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

          Apologies for the confusion. I'm using a python. Just starting out

          Thanks for the reference, but I'm not quite sure how to use it.

          Here is what I have so far

          import c4d
          from c4d import gui 
           
          Green        = 100
          
          class Colorizer(gui.GeDialog):
              
              def CreateLayout(self):
                  
                  self.SetTitle('Colorizer')
                  
                  self.BitmapButtonCustomGui(BITMAPBUTTON_BACKCOLOR = c4d.Vector(0,1,0))
                  #self.AddButton    (Green       , c4d.BFH_CENTER ,name='Green')
                                   
          def main():
              dialog = Colorizer()
              dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=300,defaulth=100)
               
          if __name__=='__main__':
              main()
          

          Currently, it returns an error of AttributeError: 'Colorizer' object has no attribute 'BitmapButtonCustomGui'.

          Is there a way around this? Thank you

          1 Reply Last reply Reply Quote 0
          • a_blockA
            a_block
            last edited by

            Hi,

            thanks for the additional information and setting the tags.

            The BitmapButton needs to be added to the dialog via AddCustomGui().
            For example like so:

                    # Prepare a red bitmap for the button.
                    w = 50
                    h = 50
                    bmpRed = c4d.bitmaps.BaseBitmap()
                    bmpRed.Init(w, h)
                    for y in xrange(w):
                        for x in xrange(h):
                            bmpRed.SetPixel(x, y, 255, 0, 0)
                    # BitmapButton configuration
                    bcBitmapButton = c4d.BaseContainer()
                    bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
            
                    # Add a BitmapButton to the dialog.
                    # _bitmapButton is a member variable of the dialog class
                    buttonId = 2000
                    _bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
                    if _bitmapButton is None:
                        print "Handle this error!"
                    # Assign the image to the button.
                    # Note: Let it create an internal copy as the created bitmap will be free'd, when scope is left.
                    _bitmapButton.SetImage(bmpRed, True)
            

            Cheers,
            Andreas

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

              Thank you for taking the time to make the code and make comments. Appreciate it alot.
              The GUI creation is resolved but can I ask how do I connect the button (Red/Green bitmap) to the command.

              I tried modifying and confirming the button ID and the command ID but does not seem to work.
              You can see the work here (and sorry again for the trouble)

              import c4d
              from c4d import gui 
               
              mainLayout = 1000
              bnRed      = 1001
              bnGreen    = 1002
              bnBlue     = 1003
              
              class Colorizer(gui.GeDialog):
                  
                  def CreateLayout(self):
                      
                      self.SetTitle('Colorizer')
                      # Prepare a red bitmap for the button.
                      self.GroupBegin   (mainLayout, c4d.BFV_CENTER, cols=2,rows=3)
                      w = 25
                      h = 25
                      bmpRed = c4d.bitmaps.BaseBitmap()
                      bmpRed.Init(w, h)
                      for y in xrange(w):
                          for x in xrange(h):
                              bmpRed.SetPixel(x, y, 255, 0, 0)
                      # BitmapButton configuration
                      bcBitmapButton = c4d.BaseContainer()
                      bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
              
                      # Add a BitmapButton to the dialog.
                      # _bitmapButton is a member variable of the dialog class
                      #buttonId = 2000
                      _bitmapButton = self.AddCustomGui(bnRed, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
                      if _bitmapButton is None:
                          print "Handle this error!"
                      # Assign the image to the button.
                      # Note: Let it create an internal copy as the created bitmap will be free'd, when scope is left.
                      _bitmapButton.SetImage(bmpRed, True)
              
                      bmpGreen = c4d.bitmaps.BaseBitmap()
                      bmpGreen.Init(w, h)
                      for y in xrange(w):
                          for x in xrange(h):
                              bmpGreen.SetPixel(x, y, 0, 255, 0)
                      
                      bcBitmapButton = c4d.BaseContainer()
                      bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
              
                      _bitmapButton = self.AddCustomGui(bnGreen, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
                      if _bitmapButton is None:
                          print "Handle this error!"
                      
                      _bitmapButton.SetImage(bmpGreen, True)
              
                      self.GroupEnd()
                      return True
              
              
                  def colorRed (self,id,msg):
                      if id == bnRed:
                          op[c4d.ID_BASEOBJECT_USECOLOR] = 2
                          op[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector (1,0,0)
                  
                          c4d.EventAdd()
                          self.Close()
              
                      return True
              
                  def colorGreen (self,id,msg):
                      if id == bnGreen:
                          op[c4d.ID_BASEOBJECT_USECOLOR] = 2
                          op[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector (1,0,0)
                  
                          c4d.EventAdd()
                          self.Close()
              
                      return True
              
                                       
              def main():
                  dialog = Colorizer()
                  dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=300,defaulth=100)
                   
              if __name__=='__main__':
                  main()
              
              1 Reply Last reply Reply Quote 0
              • a_blockA
                a_block
                last edited by

                Hi,

                you have to react to the button in your GeDialog implementation, namely in the Command() function.
                See for example these lines in the Py-TextureBaker example.

                So picking up my example snippet from above, the Command function could look like so:

                    def Command(self, id, msg):
                        if id==2000: # corresponds to the button ID used in the code snippet in the first answer in this thread
                            print "My Bitmap Button"
                        return True
                

                Cheers,
                Andreas

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

                  Hi Andreas,

                  Thank you for the response and apologies for dragging this further.

                  The code you have given works only for "print" command. But when I added my block of commands, it doesn't work on anything.

                  The code in question is (please see comments)

                     def Command (self,id,msg):
                          if id == 2000:
                            
                              print "My Bitmap Button" # this code works
                              op[c4d.ID_BASEOBJECT_USECOLOR] = 2 #However, the following two do not.
                              op[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector (1,0,0) #They work on a standalone script but on this button
                      
                          return True
                  

                  Sorry for the trouble I'm just a newbie on scripting in general. Is there other prerequisite on executing the code?

                  1 Reply Last reply Reply Quote 0
                  • a_blockA
                    a_block
                    last edited by

                    Hi,

                    no worries, we'll get you there.

                    One recommendation: When doing Python development, have the Cinema 4D Console window open (Menu Script -> Console...). There you will be presented with errors.

                    I think, your problem will be, that you try to access op, probably intending to change parameters of the active object. In Script Manager doc and op are global variables predefined for convenience. In a plugin, you have to get these yourself using GetActiveDocument() and GetActiveObject().

                    Bye,
                    Andreas

                    B 1 Reply Last reply Reply Quote 3
                    • B
                      bentraje @a_block
                      last edited by

                      @a_block

                      Case solved! Thanks again for your patience.

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