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

    Snap to grid while MouseDrag()

    Cinema 4D SDK
    2023 python
    2
    2
    411
    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.
    • P
      pim
      last edited by pim

      I have a ToolData plugin where the user can draw Planes.
      I use MouseInput() to get the inital point and then MouseDragStart() and MouseDrag() to get the other point of the Plane.

      Is there a way to snap to the grid using MouseDragStart() and MouseDrag() or is that something I have to do myself?
      Something like snapPoint = grid_size * round(point / grid_size)

                  mousex = msg[c4d.BFM_INPUT_X]
                  mousey = msg[c4d.BFM_INPUT_Y]
                  
                  leftTop = c4d.Vector(mousex, mousey, 0)
                  win.MouseDragStart(c4d.KEY_MLEFT, mousex, mousey, c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE|c4d.MOUSEDRAGFLAGS_NOMOVE)
      
                  color = c4d.Vector(256,256,256)
                  bd.SetMatrix_Screen()   #Use the screen's matrix to draw on
                      
                  mx = mousex
                  my = mousey
                  while True:
                      result, dx, dy, channels = win.MouseDrag()
                      if result!=c4d.MOUSEDRAGRESULT_CONTINUE: break
                      mx += dx
                      my += dy
                      
                      rightBottom = c4d.Vector(mx, my,0)
                      self.v1 = leftTop
                      self.v2 = rightBottom
      
                      bd.SetDepth(True) 
                      c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION)
      
      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @pim
        last edited by

        Hello @pim,

        Thank you for reaching out to us. It depends a bit on what you expect to happen here.

        There is the snapping module of Cinema 4D but you cannot actually get values out of it, i.e., you cannot compute the snapped value of x with it, you can only define the snap settings with it.

        But when I understand your correctly, you just want to quantize some mouse inputs for a plugin and for that you must indeed compute the values yourself. It is best to also draw a snapping location onto the screen, so that user can see where the actual input is in relation to the mouse.

        How the snapping works in detail depends on what you want to do exactly when quantizing your plane drawing. The snapping module might become relevant here, because with it you can retrieve the working planes, which might be useful when placing planes.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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