Access the measurement tool output from a plugin

Hi!
I’d like to access the coordinates of the two points defined when using the measurement tool in Edit mode (not the measurement line from text mode) from a plugin. More precisely, I want to draw stuff in the active glyph view and be able to use the measurement tool on that.
How can I know when the tool is used, and have the coordinates from the mouse down -> mouse dragged points so I can use intersectionsBetweenPoints() on the layer I’m drawing and do stuff accordingly?

Did some digging, figured out a way. Here is a simple callback function that can be run from the Macro panel to get the coordinates of the entry / exit points of the measurement tool, only when used in Edit mode:

def get_measurement_in_out(Layer,info):
  try:
    activeMode = Glyphs.currentDocument.windowController().toolDrawDelegate()
    activeTool = Glyphs.currentDocument.windowController().toolEventDelegate()
    if activeMode.__class__.__name__ == "GlyphsToolSelect" and activeTool.__class__.__name__ == "GlyphsToolMeasurement":
      entry = activeTool.intersections()[0]
      exit = activeTool.intersections()[-1]
      print(entry, exit)
  except:
    import traceback
    print(traceback.format_exc())
Glyphs.addCallback(get_measurement_in_out, DRAWBACKGROUND)

Georg, let me know if there’s a better way!

That is pretty good.
If you do that from a reporter, you can access self.controller instead of Glyphs.currentDocument.windowController()
And I needed to activeTool.className() == "GlyphsToolMeasurement" as the python version adds some stuff to the class name.

2 Likes