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

    DrawLine2D on top of everything else

    Cinema 4D SDK
    r20 python
    3
    6
    1.0k
    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

      I have a toolplugin and in MouseInput() I draw some lines using bd.DrawLine2D().
      Now I read in a old post that "Yep, drawing only in the Draw procedures. πŸ˜‰ Anything else could even crash the program!"

      But how and what do I put in Draw()?
      I do for example

      v1 = c4d.Vector(100,100,0)
      v2 = c4d.Vector(200,200,0)
      DrawLine2D((100,100,0), (200,200,0))
      

      How to put this in Draw()?

      1 Reply Last reply Reply Quote 0
      • C4DSC
        C4DS
        last edited by

        I don't get the question, actually.
        What's wrong with doing

        def Draw(self, doc, data, bd, bh, bt, flags):
        
          v1 = c4d.Vector(100,100,0)
          v2 = c4d.Vector(200,200,0)
          bd.SetPen(...
          bd.DrawLine2D(v1, v2)
        
        
        1 Reply Last reply Reply Quote 0
        • P
          pim
          last edited by pim

          Sorry, I was not clear enough.

          I get the coordinates (v1 and v2) in MouseInput().
          So, how to get the coordinates I got from MouseInput() to Draw().
          Just call MouseInput() in Draw() or use (class) variables to be able to use v1 and v2 in Draw()?

          Something like this?

          class PlaceTool(c4d.plugins.ToolData):       	
          
              v1 = c4d.Vector(0,0,0)
              v2 = c4d.Vector(0,0,0)
              
              def Draw(self, doc, data, bd, bh, bt, flags):	
                  bd.SetPen(c4d.Vector(256,256,256))
                  bd.DrawLine2D(self.v1, self.v2)
                  return True
                  
              def MouseInput(self, doc, data, bd, win, msg):
                  self.v1 = c4d.Vector(0,0,0)
                  self.v2 = c4d.Vector(msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y], 0)
                  return True
          

          Is MouseInput() always called before Draw()?

          By the way, compliments on implementing Undo's in the sdk.
          It was quite easy for me to implement Undo functionality.

          1 Reply Last reply Reply Quote 0
          • P
            pim
            last edited by

            I did some more testing and I think I got it now.
            In MouseInput() get and set your coordinates.
            Then call c4d.DrawViews(). This will call Draw(), where you can (and should) do the drawing like bd.DrawLine2D().

            class PlaceTool(c4d.plugins.ToolData):       	
            
                v1 = c4d.Vector(0,0,0)
                v2 = c4d.Vector(0,0,0)
                
                def Draw(self, doc, data, bd, bh, bt, flags):	
                    bd.SetPen(c4d.Vector(256,256,256))
                    bd.DrawLine2D(self.v1, self.v2)
                    return True
                    
                def MouseInput(self, doc, data, bd, win, msg):
                    self.v1 = c4d.Vector(0,0,0)
                    self.v2 = c4d.Vector(msg[c4d.BFM_INPUT_X], msg[c4d.BFM_INPUT_Y], 0)
                    c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK)  #Added 
                    return True
                    
                    
            
            1 Reply Last reply Reply Quote 1
            • M
              m_adam
              last edited by

              Hi @pim nothing really to add here, just that you are correct in MouseInput you have to retrieve the coordinates you want, store them, and in the Draw draw them.
              You can find an example in Py-LiquidPainter.pyp.

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • P
                pim
                last edited by

                Thanks.
                Pim

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