
// Script function: Measure the length of a line
// Requirement: Draw a "Line Annotation" or "Line with length label" on the front-most image


// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined 
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html


// Get the front-most image
Image GlobalSinoImage:=Getfrontimage()
Imagedisplay EMimage=GlobalSinoImage.Imagegetimagedisplay(0)

Component GlobalSinoLine=EMimage.Componentgetnthchildoftype(2, 0)
GlobalSinoLine.Componentisselected()

// Get the coordinate of the start and end of the line in pixel
number EMx0, EMy0, EMx, EMy
GlobalSinoLine.Componentgetcontrolpoint(4, EMx0, EMy0)
GlobalSinoLine.Componentgetcontrolpoint(7, EMx, EMy)

// Calculate the length of the line in pixel
number EMline=sqrt((EMx-EMx0)**2+(EMy-EMy0)**2)

// Get the calibration information of the image
number EMscale, EMorigin
string EMunits
GlobalSinoImage.Imagegetdimensioncalibration(0, EMorigin, EMscale, EMunits, 1)

// Calibrate the line length into the scale units of the image
EMline=EMline*EMscale

Result("Line length:\t"+format(EMline, "%10.2f")+"\t"+EMunits+"\n")

Showalert("Line length:"+format(EMline,"%10.2f")+" "+EMunits, 2)