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

    Bitmap Button

    Cinema 4D SDK
    python
    2
    14
    2.6k
    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.
    • merkvilsonM
      merkvilson
      last edited by merkvilson

      Hello PluginCafe! 🙂

      I need to implement some sort of custom viewport or a custom material preview window in my object modifier or object generator plugin.

      something like this:

      0_1549526487243_80b0859e-cd0e-4332-b76d-b1913d75c8fc-image.png

      Is it possible using python?

      As I know, there is a BitmapButtonCustomGui class and maybe it can be used in order to accomplish this task, but I never used it and don't know how it works.

      any tips or better ideas? 🙂

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by s_bach

        Hello,

        there is no thing like a custom viewport.

        You can render a given scene (BaseDocument) with RenderDocument() using the hardware (OpenGL) renderer. Then you can display the resulting BaseBitmap in the GUI somehow. That is what the material preview is doing.

        One way would be to use a GeDialog. In this case you could use a BitmapButtonCustomGui to display a BaseBitmap. This is something you could implement in Python.

        Another way could be to add a bitmap button to the description of your object (CUSTOMDATATYPE_BITMAPBUTTON). Such a bitmap button would display a registered icon (BITMAPBUTTON_ICONID1). So you would have to register your bitmap as an icon using RegisterIcon(). But I haven't tried that and I don't know how well that would work.

        A third solution would be to use the C++ SDK. Then you could define a custom data type which you could add to your object's parameter description. You could create a custom GUI for that data type that includes a GeUserArea that draws the bitmap the way you want.

        You find more information on parameter descriptions in these manuals:

        • Description Manual
        • Description Settings Manual

        And more information on GeDialogs and GeUserAreas in these manuals:

        • GeDialog Manual
        • GeUserArea Manual

        You find examples on how to create custom data types or custom GUI elements in C++ here:

        • customgui_string.cpp
        • customdata_customgui.cpp

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • merkvilsonM
          merkvilson
          last edited by merkvilson

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • merkvilsonM
            merkvilson
            last edited by

            Seems like I figured it out but I'll keep investigating.

            1 Reply Last reply Reply Quote 0
            • merkvilsonM
              merkvilson
              last edited by merkvilson

              I tried this way and it kinda works. but let's assume that I want to scale the sphere object from my object generator plugin. It works only if I'm updating the render settings or reloading python plugins. Is it possible to update it according to the DIRTY FLAGS of the object generator plugin?

              let me know if I'm doing something wrong.

              1 Reply Last reply Reply Quote 0
              • S
                s_bach
                last edited by

                Hello,

                you could set DIRTYFLAGS_DESCRIPTION after an interaction with the TEST_SLIDER parameter (e.g. in SetDParameter or after MSG_DESCRIPTION_POSTSETPARAMETER). That should update the description.

                best wishes,
                Sebastian

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                merkvilsonM 1 Reply Last reply Reply Quote 1
                • merkvilsonM
                  merkvilson @s_bach
                  last edited by

                  @s_bach

                  SetDParameter seems to be easier but seems like I'm doing something wrong. Can you provide a code snippet, how to do this properly?

                  1 Reply Last reply Reply Quote 0
                  • merkvilsonM
                    merkvilson
                    last edited by

                    I'm probably doing something wrong.

                        def SetDParameter(self, node, id, t_data, flags) :   
                    
                            if id[0].id == c4d.TEST_SLIDER:
                                node.SetDirty(c4d.DIRTYFLAGS_DESCRIPTION)
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • S
                      s_bach
                      last edited by

                      Hello,

                      it seems to work better if you change the dirty status of the bitmap. Something like this:

                      def GetDParameter(self, node, id, flags):
                          if id[0].id == c4d.THE_BITMAP_BUTTON:
                              data = c4d.BitmapButtonStruct(node, id, self.bmp.GetDirty())
                              return (True, data, flags | c4d.DESCFLAGS_GET_PARAM_GET)
                          
                          return True
                      
                      def SetDParameter(self, node, id, t_data, flags):
                      
                          if id[0].id == c4d.THE_OTHER_PARAMETER:
                              self.bmp.SetDirty()
                              node.SetDirty(c4d.DIRTYFLAGS_DATA)
                      
                          return False
                      

                      best wishes,
                      Sebastian

                      MAXON SDK Specialist

                      Development Blog, MAXON Registered Developer

                      1 Reply Last reply Reply Quote 1
                      • merkvilsonM
                        merkvilson
                        last edited by merkvilson

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • merkvilsonM
                          merkvilson
                          last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • merkvilsonM
                            merkvilson
                            last edited by merkvilson

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • merkvilsonM
                              merkvilson
                              last edited by merkvilson

                              btw, is it possible to prevent the description from constant updates during manipulating the slider and set the DIRTYFLAGS when the slider is already set to the desired value?
                              Seems like C4D's material preview is capable of detecting time intervals between manipulations and if the interval is not high enough, no update takes place. Should I import pythons datetime or maybe it is possible to accomplish this task directly from c4d's module?

                              1 Reply Last reply Reply Quote 0
                              • merkvilsonM
                                merkvilson
                                last edited by

                                This goes off topic so I'll make a new post.

                                The main issue is already solved, thanks to Sebastian! 💙

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