DrawLine2D on top of everything else



  • 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()?



  • 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)
    
    


  • 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.



  • 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
            
            
    


  • 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.



  • Thanks.
    Pim


Log in to reply