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

    [SOLVED]Start Drag from GeUserArea

    PYTHON Development
    0
    19
    3.3k
    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
      Helper
      last edited by

      On 08/06/2017 at 09:38, xxxxxxxx wrote:

      Thanks you. Tested and solved ! 🙂

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

        On 09/06/2017 at 00:54, xxxxxxxx wrote:

        Sorry to bump this thread but is there a way for start drag from a GeUserArea and recieve drop message from TreeViewCustomGui? Or at least is it possible to send message to this TreeViewCustomGui? Or a timer? 
        Just tell me yes or no 😉

        Cause I think I must do the following thing but I prefer ask if there is no other way before ^^
        Make my timer function into my GeDialog who call a custom timer function inside my TreeView 🙂

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

          On 09/06/2017 at 02:29, xxxxxxxx wrote:

          GeUserArea.HandleMouseDrag() is missing in the Python API so it would be really difficult and hacky to send drag and drop data to other gadgets.

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

            On 09/06/2017 at 02:46, xxxxxxxx wrote:

            Ok thanks for confirming ! 🙂

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

              On 09/06/2017 at 13:53, xxxxxxxx wrote:

              Sorry again to bump this thread, but I don't udnerstand the output code while the mouse is not moving, delta y is always -22 while it should be 0

                  def InputEvent(self, msg) :
                      mousex = msg[c4d.BFM_INPUT_X]
                      mousey = msg[c4d.BFM_INPUT_Y]
                
                      self.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE | c4d.MOUSEDRAGFLAGS_NOMOVE)
                
                      start_x = mousex
                      start_y = mousey
                
                      mx = mousex
                      my = mousey
                      state = c4d.BaseContainer()
                      while True:
                
                          result, dx, dy, channels = self.MouseDrag()
                          if result == c4d.MOUSEDRAGRESULT_ESCAPE:
                              break
                
                          if not self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state) :
                              break
                
                          if state[c4d.BFM_INPUT_VALUE] == 0:
                              print "Released Left Mouse"
                              break
                
                          if dx == 0 and dy == 0: #dy != 0 while not moving
                              continue
                
                          mx += dx
                          my += dy
                
                         #Should not be display if not moving
                         print 'drag'
                
                      print start_x - mx
                      print start_y - my #-22 if not moving
                
                      return True
              
              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 12/06/2017 at 07:06, xxxxxxxx wrote:

                Originally posted by xxxxxxxx

                Sorry again to bump this thread, but I don't understand the output code while the mouse is not moving, delta y is always -22 while it should be 0

                If the mouse doesn't move dx and dy are 0. The final mouse delta X and Y values depends on how you calculate the current mouse position.
                It's better to subtract the mouse drag delta values:

                mx -= dx
                my -= dy
                

                Then the final delta value can be calculated:
                print mx - mousex
                print my - mousey

                If you don't want MouseDrag() to return when the mouse doesn't move, don't pass MOUSEDRAGFLAGS_NOMOVE to MouseDragStart().

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

                  On 13/06/2017 at 04:52, xxxxxxxx wrote:

                  Ok I get why it's wrong... The corect loop initialization is:

                          mousex = msg[c4d.BFM_INPUT_X]
                          mousey = msg[c4d.BFM_INPUT_Y]
                          
                          self.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE | c4d.MOUSEDRAGFLAGS_NOMOVE)
                          
                          while self.MouseDrag()[0] == c4d.MOUSEDRAGRESULT_CONTINUE:
                              if msg[c4d.BFM_INPUT_VALUE] == 0:
                                  break
                              
                              result, dx, dy, channels = self.MouseDrag()
                              print "dx {} - dy {}".format(dx, dy)
                  

                  While in the documention of https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/EditorWindow/index.html#EditorWindow.MouseDragStart the main drag loop is done with While true, which give you a wrong value for dx/dy for the first packet of the drag input.

                  So doing it like in the C++ exemple

                      win->MouseDragStart(button, mouseX, mouseY, MOUSEDRAGFLAGS_DONTHIDEMOUSE | MOUSEDRAGFLAGS_NOMOVE);
                      while (win->MouseDrag(&dx, &dy, &device) == MOUSEDRAGRESULT_CONTINUE)
                  

                  give us in python

                          self.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE | c4d.MOUSEDRAGFLAGS_NOMOVE)
                          
                          while self.MouseDrag()[0] == c4d.MOUSEDRAGRESULT_CONTINUE:
                  

                  Anyway thanks for your support ! 🙂

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

                    On 13/06/2017 at 08:18, xxxxxxxx wrote:

                    I can't confirm that because the delta values returned from the call to MouseDrag()[0] aren't processed for each while loop:

                    while self.MouseDrag()[0] == c4d.MOUSEDRAGRESULT_CONTINUE: # dx, dy and channels not retrieved and processed
                    

                    There should be only one MouseDrag() call for each while loop.

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

                      On 13/06/2017 at 08:28, xxxxxxxx wrote:

                      Juste copy paste thoses two codes and do a normal click without dragging. Just a simple click (no move, nothing just a click), So result should be 0 and 0 for dx/dy in all case (in all packet of the drag pool)
                      The first one give correct result for dx , dy

                      import c4d
                        
                      class Area(c4d.gui.GeUserArea) :
                        
                          def InputEvent(self, msg) :
                              mousex = msg[c4d.BFM_INPUT_X]
                              mousey = msg[c4d.BFM_INPUT_Y]
                              
                              self.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE | c4d.MOUSEDRAGFLAGS_NOMOVE)
                              
                              while self.MouseDrag()[0]:
                                  if msg[c4d.BFM_INPUT_VALUE] == 0:
                                      break
                                  
                                  result, dx, dy, channels = self.MouseDrag()
                                  if result!=c4d.MOUSEDRAGRESULT_CONTINUE: break
                                  
                                  print "dx {} - dy {}".format(dx, dy)
                                              
                              return True
                        
                      class MyDialog(c4d.gui.GeDialog) :
                          def CreateLayout(self) :
                              self.area = Area()
                              
                              self.AddUserArea(1000, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT)
                              self.AttachUserArea(self.area, 1000)
                              return True
                        
                      def main() :
                          dialog = MyDialog()
                          dialog.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500, defaulth=500)
                        
                      if __name__=='__main__':
                          main()
                      

                      While the sdk code(using While True) give wrong result for dx, dy in the first packet (dx 4 and dy 4)

                      import c4d
                        
                      class Area(c4d.gui.GeUserArea) :
                        
                          def InputEvent(self, msg) :
                              mousex = msg[c4d.BFM_INPUT_X]
                              mousey = msg[c4d.BFM_INPUT_Y]
                              
                              self.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE | c4d.MOUSEDRAGFLAGS_NOMOVE)
                              
                              while True:
                                  if msg[c4d.BFM_INPUT_VALUE] == 0:
                                      break
                                  
                                  result, dx, dy, channels = self.MouseDrag()
                                  if result!=c4d.MOUSEDRAGRESULT_CONTINUE: break
                                  
                                  print "dx {} - dy {}".format(dx, dy)
                                              
                              return True
                        
                      class MyDialog(c4d.gui.GeDialog) :
                          def CreateLayout(self) :
                              self.area = Area()
                              
                              self.AddUserArea(1000, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT)
                              self.AttachUserArea(self.area, 1000)
                              return True
                        
                      def main() :
                          dialog = MyDialog()
                          dialog.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500, defaulth=500)
                        
                      if __name__=='__main__':
                          main()
                      
                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 14/06/2017 at 03:17, xxxxxxxx wrote:

                        You're not retrieving and printing the delta values dx and dy from the self.MouseDrag()[0] calls in the first script. The delta values are 4.0 for the first mouse drag there too.

                        The limitation with MouseDrag() in Python is the language doesn't support assignments in expressions.

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