Hello,
This is my first time attempting to do a display conduit and I’m a bit stuck and would appreciate some guidance!
I’m attempting to start out by simply drawing a red, filled circle at the location of the mouse when the user has a mouse button down OnMouseDown (in this case the middle mouse button) and removing this circle from the viewport OnMouseUp.
I have debugging statements in place and know that my mouse events are occurring but I’m confused how to implement HUD/viewport drawing within the mouse events or how to call them properly. Perhaps it’s not that but I’m just not understanding how to actually draw/display the graphic on the viewport via the display.conduit.
Thanks for your response!
Here’s the code I have so far:
import Rhino
import scriptcontext as sc
import System
from System.Drawing import Color
class MiddleMouseCallback(Rhino.UI.MouseCallback):
def OnMouseDown(self, e):
if e.Button == System.Windows.Forms.MouseButtons.Middle:
Rhino.RhinoApp.WriteLine("Middle mouse down")
# Store the mouse location when the middle mouse button is pressed
self.mouse_down_location = e.Location
else:
Rhino.RhinoApp.WriteLine("Other mouse down")
def OnMouseUp(self, e):
if e.Button == System.Windows.Forms.MouseButtons.Middle:
Rhino.RhinoApp.WriteLine("Middle mouse up")
else:
Rhino.RhinoApp.WriteLine("Other mouse up")
class CircleConduit(Rhino.Display.DisplayConduit):
def __init__(self, mouse_down_location):
super(CircleConduit, self).__init__()
self.mouse_down_location = mouse_down_location
def DrawForeground(self, e):
if hasattr(self, 'mouse_down_location'):
radius = 220
# Draw the filled circle
circle = Rhino.Display.DisplayPipeline.DrawCircle(self.mouse_down_location, radius)
e.Display.DrawCircle(circle, Color.Red, True)
def TestSampleMouseCallback():
# Initialize the mouse callback
if sc.sticky.has_key('TestSampleMouseCallback'):
callback = sc.sticky['TestSampleMouseCallback']
if callback:
callback.Enabled = False
callback = None
sc.sticky.Remove('TestSampleMouseCallback')
else:
callback = MiddleMouseCallback()
callback.Enabled = True
sc.sticky['TestSampleMouseCallback'] = callback
if __name__ == "__main__":
# Call the test function
TestSampleMouseCallback()