English

How To: Capture two Apply mouse clicks

Procedure

This document shows how to use the Apply property of a tool to capture two or more mouse clicks in the View display.

Answer:

The request "ReturnUserPoint" returns the location of the cursor in the
display, regardless of where or whether the mouse button is clicked. This
occurs because the request is placed within a tool "Apply" script. This is
probably the most popular place to use this request, so it is important to know
that the request does not return the location of the mouse click, it returns
the location of the mouse cursor at the point the script runs the request.

The following two scripts provide an example of how to capture two mouse clicks from a tool's "Apply" event. In the following example, the two clicks are used to generate a distance, then that value is sent to a message box. Write and compile these two scripts, then place them as the "Click" and "Apply" events on a new tool on the View GUI.

Select the tool, it will initialize the two point variables to be null. Make a
single click in the View display. Then you can make a second click in the View
display anywhere else. After the second click, a message box will display the
distance between the two clicks, and then re-initializing the point variables
to be null. The tool can then be re-used as long as it continues to be the
selected tool.

You can modify the second script to capture three or more clicks, or send the
results somewhere other than a MsgBox, or perform some other calculation after the second click, etc.

'--- Script: "InitPointGlobals.ave"
'
'--- Place this script as the "Click" property of a new tool.
_firstPoint = Point.MakeNull
_secondPoint = Point.MakeNull
'
'--- End of script: "InitPointGlobals.ave"

'--- Script: "DoubleClickDistance.ave"
'
'--- Place this script as the "Apply" property of the same new tool.
theView = av.GetActiveDoc
theDisplay = theView.Getdisplay
if (_firstPoint.IsNull)
then
_firstPoint = theDisplay.ReturnUserPoint
return nil
else
_secondPoint = theDisplay.ReturnUserPoint
dist = _firstPoint.Distance(_secondPoint)
distString = dist.SetFormat("d.dddd").AsString
MsgBox.Info(distString,"")
_firstPoint = Point.MakeNull
_secondPoint = Point.MakeNull
end
'
'--- End of script: "DoubleClickDistance