Measure angle by 3 points with dynamic draw (12d App)

Source code and compiled test macro demonstrating my library for user measurement of an angle by picking 3 points with dynamic drawing of the pick and measurement.  This code was initially written for the Rotate Relative macro (Utilities→H-Z→Rotate relative) and was based on the behaviour of the in-built Measure Angle by 3pts (Utilities→Measure→Angle x 3pts). The behaviour of this code is, however, slightly different in the order of picks with the base point being picked first.

The main complexity involved in this code is the use of a callback function. A callback function is a programming concept whereby a function (A) is passed to and called by another function (B). This is provided to allow the code to be included as-is in other macros without the need to drastically modify or re-write the library code to suit each situation. The callback implemented here is not a true callback due to limited support in the 12d Programming Language, but is an attempt to provide such functionality. Basically, there is a function, FW_Angle_3pts_mouse_event() that is regularly called on each action whilst the measure and selection is running.

This function is declared, but not implemented in the library. It is up to the author of the macro including this library to write the implementation of this function. The bare minimum would be:

A more useful implementation is shown in the test macro and at the bottom of the library source file that updates the panel widgets with values returned during the measurement and selection process. Without this, the measured angle would typically only be shown once the entire measurement process has been completed. With the callback functionality, the angle can be dynamically updated to reflect the current cursor before completion.

It’s not perfect or ideal and is missing a lot of error-checking code, so leave a comment if you have any questions or feedback. I’d also be interested in hearing if you find this useful. I do/had planned to create an equivalent library for other measurements.

Refer to LICENSE in zip file for license terms.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.