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

    GeUserArea Question

    Scheduled Pinned Locked Moved SDK Help
    13 Posts 0 Posters 1.1k Views
    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.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 11/05/2012 at 09:32, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   13 
      Platform:   Windows  ; Mac  ;  
      Language(s) :     C++  ;

      ---------
      I would like to create a user interface that allows users to click on an image in a dialogue and that will then select items in the scene.  Similar to visual Selector..    Is this something I achieve using the GeUserArea class?  You can either answer with yes or no or elaborate,  lol  I am happy with either.  😄

      Thanks,

      Shawn

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 11/05/2012 at 09:41, xxxxxxxx wrote:

        yes that's it. 😉
        i can give you some py for rederence later .

        cheers,

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 11/05/2012 at 09:47, xxxxxxxx wrote:

          Thanks Niklas,   I will look in to it.  🙂

          ~Shawn

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 11/05/2012 at 21:03, xxxxxxxx wrote:

            Can GeUserArea only be used in a dialog or can it be added to the attributes manager?

            Thanks,

            Shawn

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 11/05/2012 at 23:55, xxxxxxxx wrote:

              I don't think so, but afaik you can subclass a CustomGui, can't you? CustomGui's can be added in both.

              Cheers,

              PS: Here ya go, ready for the script-manager, you only have to add some paths to your icons you want to show.

                
              import c4d  
                
              class BaseElement(object) :  
                
                def __init__(self) :  
                    self.last_region = 0, 0, 0, 0  
                
                def __contains__(self, (x, y)) :  
                    x1, y1, x2, y2 = self.last_region  
                    return (x1 <= x <= x2 and y1 <= y <= y2)  
                
                def render(self, area, x, y) :  
                    pass  
                
              class BitmapElement(BaseElement) :  
                
                def __init__(self, id, bmp, x, y) :  
                    super(BitmapElement, self).__init__()  
                
                    self.id  = id  
                    self.bmp = bmp  
                    self.x   = x  
                    self.y   = y  
                
                def render(self, area, x=0, y=0) :  
                    x += self.x  
                    y += self.y  
                    w, h = self.bmp.GetSize()  
                    self.last_region = (x, y, x + w, y + h)  
                    area.DrawBitmap(self.bmp, x, y, w, h,  
                                    0, 0, w, h, c4d.BMP_NORMAL)  
                
              class BitmapGroup(BaseElement) :  
                
                COLOR_BG = c4d.Vector(0.21, 0.19, 0.27)  
                
                def __init__(self, x, y, w, h) :  
                    super(BitmapGroup, self).__init__()  
                
                    self.x    = x  
                    self.y    = y  
                    self.w    = w  
                    self.h    = h  
                    self.bmps = []  
                
                def add_bitmap(self, bmp) :  
                    self.bmps.append(bmp)  
                
                def render(self, area, x=0, y=0) :  
                    x += self.x  
                    y += self.y  
                    w  = self.w  
                    h  = self.h  
                    self.last_region = (x, y, x + w, y + h)  
                    area.SetClippingRegion(self.x, self.y, self.x + w, self.y + h)  
                    if self.COLOR_BG:  
                        area.DrawSetPen(self.COLOR_BG)  
                        area.DrawRectangle(x, y, x + w, y + h)  
                    for bmp in self.bmps:  
                        bmp.render(area, x, y)  
                    area.ClearClippingRegion()  
                
                def what_bitmap(self, x, y) :  
                    if (x, y) not in self:  
                        return  
                    hit_bmp = None  
                    for bmp in self.bmps:  
                        if (x, y) in bmp:  
                            hit_bmp = bmp  
                    return hit_bmp  
                
              class UserArea(c4d.gui.GeUserArea) :  
                
                COLOR_BG = c4d.Vector(.21)  
                
                def __init__(self) :  
                    self.bmpgroup = BitmapGroup(0, 0, 0, 0)  
                
                def GetMinSize(self) :  
                    return (100, 80)  
                
                def DrawMsg(self, x1, y1, x2, y2, msg) :  
                    self.DrawSetPen(self.COLOR_BG)  
                    self.DrawRectangle(x1, y1, x2, y2)  
                
                    # adapt size of the bmpgroup  
                    self.bmpgroup.x = x1  
                    self.bmpgroup.y = y1  
                    self.bmpgroup.w = x2 - x1  
                    self.bmpgroup.h = y2 - y1  
                    self.bmpgroup.render(self, x1, y1)  
                
                
                def InputEvent(self, msg) :  
                    if msg[c4d.BFM_INPUT_DEVICE] == c4d.BFM_INPUT_MOUSE:  
                        x, y = msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y]  
                        g2l  = self.Global2Local()  
                        x += g2l['x']  
                        y += g2l['y']  
                        if msg[c4d.BFM_INPUT_CHANNEL] == c4d.BFM_INPUT_MOUSELEFT:  
                            bmp = self.bmpgroup.what_bitmap(x, y)  
                            if bmp:  
                                self.bitmap_clicked(bmp, bmp.id)  
                    return True  
                
                # new  
                
                def bitmap_clicked(self, bmp, id) :  
                    # TODO: implement what happens when Bitmap is clicked  
                    print "Bitmap with id", id, "was clicked!"  
                    pass  
                
              class Dialog(c4d.gui.GeDialog) :  
                
                def __init__(self, ua) :  
                    self.ua = ua  
                
                def CreateLayout(self) :  
                    self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)  
                    self.AttachUserArea(self.ua, 1000)  
                    return True  
                
              def main() :  
                ua = UserArea()  
                dlg = Dialog(ua)  
                
                # Add bitmaps to the BitmapGroup with an offset of 50 pixels  
                paths = []      # add your icons or whatever here  
                for i, path in enumerate(paths) :  
                    bmp = c4d.bitmaps.BaseBitmap()  
                    bmp.InitWith(path)  
                    bmp = BitmapElement(i, bmp, i * 50, 0)  
                    ua.bmpgroup.add_bitmap(bmp)  
                
                
                
                dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE)  
                
              if __name__ == "__main__":  
                main()
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 13/05/2012 at 12:53, xxxxxxxx wrote:

                Some response would be quite nice. Those code-snippets don't just fly through the window after calling my big-friend Coding God.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 13/05/2012 at 13:00, xxxxxxxx wrote:

                  Lol sorry niklas. I hadn't had a chance to look at them yet. Thank you for giving me the examples. To be honest I didn't even know there was a code example because I had checked it on my phone and the email that was sent to me didn't have an example.   Sorry for the lack of response.   Thanks again.   I do appreciate your assistance.

                  -Shawn

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 14/05/2012 at 05:10, xxxxxxxx wrote:

                    So I have to excuse in return. I assumed you did already see it as you have opened another Thread at that time.

                    Best,
                    Niklas

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 14/05/2012 at 05:15, xxxxxxxx wrote:

                      Thanks again Niklas,

                      Your code has been most helpful.  🙂

                      ~Shawn

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        On 14/08/2014 at 08:14, xxxxxxxx wrote:

                        Niklas - the code you posted above, is brilliant, and i have a question:

                        Is it possible to use GeUserArea similar to the above ( ie clickable bitmaps ) but in the ObjectManager properties for a Plugin?

                        I thought itd be quicker to ask before i waste a lot of time trying something out that isnt possible!

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

                          On 14/08/2014 at 08:55, xxxxxxxx wrote:

                          I might just use the BITMAPBUTTON description element, but would be useful to know..  Plus it avoids registering icon id`s..

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            Helper
                            last edited by

                            On 14/08/2014 at 10:29, xxxxxxxx wrote:

                            Hi Eclectrik,

                            Originally posted by xxxxxxxx

                            Is it possible to use GeUserArea similar to the above ( ie clickable bitmaps ) but in the ObjectManager properties for a Plugin?

                            Not from Python, unfortunately. That would require implementing a CustomGui plugin.

                            Best,
                            -Niklas

                            PS: Wonder why I was so harsh back then, sorry for that.

                            1 Reply Last reply Reply Quote 0
                            • H Offline
                              Helper
                              last edited by

                              On 14/08/2014 at 11:15, xxxxxxxx wrote:

                              Hi Niklas - sorry i forgot to mention in this case i am using C++.

                              BTW - i would also be annoyed if i posted a whole script for somebody and didn't get any thanks for it!

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