Hi,
Pfff… Really a very artificial code, but I didn’t expect otherwise.
First, replacing the ExThreePoints.js code is not permanent, this might be overwritten on an update.
But of course you can supersede it by adding a copy to the user data location where it will not be affected.
The better option is to rename it by replacing the term ‘ExThreePoints’ throughout, including folders and filenames.
Essentially adding a new Addon tool.
We don’t set an initial state in the class constructor (Line 28).
The main action in the beginEvent of an interactive script is setting the initial state.
We might set up some defaults and I count 3 objects:
this.selectedEntity = undefined;
this.isLineEntity = undefined; // Pretty obsolete flag
this.numSegments = 16; // Default number of segments
You define (kept) 3 states but there is just 1 single state: Selecting an entity.
Also reflected in escapeEvent(), this terminates directly instead of throttling back: 2 > 1 > 0 > Cancel or finished.
Entering a number of segments on the Command Line is not regarded as a tool state.
The Command Line line may also be used to pass on a certain coordinate instead of a mouse action.
Typically this would be a tool option displayed on the Option Toolbar but then you need to define an UI.
Changing this then sets this.numSegments and that can indeed also be set by a commandEvent.
getState() is totally obsolete and never called for.
The current tool state, if any, is stored in this.state.
In the beginEvent you check for a valid Document Interface.
A: The check should be isNull(di).
B: Pretty obsolete because in the init section it is required to have a document and thus an associated interface.
C: I tend to not use qDebug or related. On Windows that can not be shown on the fly.
Any user warning/info/message is listed in the Command History.
For that my Command Line is docked at the right showing more than 1 line.
As said above, the beginEvent sets the SelectingLine state and the action enters the PickEntity mode.
Further handled by a entityPickEvent() when indicating near an entity.
In the entityPickEvent you check for a valid entity.
A: The check should be isNull(entity) and it should set this.selectedEntity = undefined;.
B: Verifying that it is a Line or a Polyline entity is simplified by better suited standard functions (library.js).
if (isLineEntity(entity) || isPolylineEntity(entity)) {
this.selectedEntity = entity;
}
else {
this.selectedEntity = undefined;
// Perhaps issue warning
}
C: About your TODO … Use the predefined and named things, don’t bother by their enumeration.
D: We don’t have to set a flag like this.isLineEntity because such a test is straightforward.
At this point it start to deviate a lot.
Not a Line or Polyline it never exits the PickEntity mode.
If yes, state SettingSegments is set but that is not a state that relies on mouse actions.
Eventually only handled by a commandEvent and passed on to the divideEntity function.
For an interactive tool that would be called by getOperation in preview or final mode.
It is there that we warn the user of having picked an unsupported entity type.
Typically with this.warnNotLineArcPolyline(); because your tool may also be coded to support Arcs.
Further I will be brief.
Line an Polyline entities both support getPointsWithDistanceToEnd(distance, from)
But that is intended for snapping to points on the entity and per line or polyline segment.
Entity based:
REntity.getPointsWithDistanceToEnd(..)
To handle things mathematically we cast the queried entity to an RShape by var shape = this.selectedEntity.castToShape();
Shape based:
RLine.getPointsWithDistanceToEnd(..)
RPolyline.getPointsWithDistanceToEnd(..)
Something an untrained AI is probably not aware of. 
There is a difference between distributing N points or dividing an entity in N virtual segments adding a point in between.
With default = 16 you get 16 points for the first and 15 points for the second method.
You can add points along the entity including at start and end or not. Preferable not for a closed Polyline.
A Polyline can be logically open and geometrically closed when start and end coincides.
Remark that at the end of the divideEntity function the state SettingPosition is set.
The tool enters the PickCoordinate mode and on a coordinateEvent it will draw 3 points (Three Points example)
Regards,
CVH