
! script name: tableinsert.d/tdistptpt
! topic: insert the distance between two points into a table

!A
!A NAME:
!A
!A 	Tables: Distance
!A
!A DESCRIPTION:
!A
!A 	This script will insert the distance between two points into a table.
!A
!B INSTRUCTIONS:
!B
!B 	STARTING POINT: Pick the first point to be used for the distance
!B 		between two points to be calculated and entered in a table.
!B
!B 	ENDING POINT: Pick the second point to be used for the distance
!B 		between two points to be calculated and entered in a table.
!B
!B 	PICK ENTRY POSITION: Pick the position in the table for the
!B 		distance between the two selected points to be entered.
!B
!B NOTES:
!B
!B      This script is not variational. The table will not update
!B      when the entity in changed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: distance into table")

DIM Answer$[256]
DIM Descr$[256]
DIM Destination$[256]
DIM Format$[15]
DEG

A= GetDefault(WsPlacesAfter)
Format$= "decimal "&VAL$(A)

Start:!
ActivateUndo
stat= SetInputFormat("n4","")
Pick_start:E1=PickEntity("STARTING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_start
T1= LastPickPara
Pick_return1= CurrPickReturn
Ps= ParameterReturnPt(E1,T1,Pick_return1)

Pick_end:Stat=SetLastPoint(Ps)
E2=PickEntity("ENDING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E2) THEN Pick_end
T2= LastPickPara
Pick_return2= CurrPickReturn
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)


Pick_entry:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK ENTRY POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Table1) THEN Pick_entry
T1= LastPickPara
R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)

ActivateUndo
Stat= AdvanceUndoNumber("length entry")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
L1=LineTwoPoints(Ps,Pe)
Stat= InsertIntoTable(Table1,EntityLength(L1),Format$,R1,C1)
Stat= TableTextOrigin(Table1,R1,C1,WsRightCenter)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
Stat= PlotEntity(Table1)

GOTO Start


Leave:!
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
