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

!A
!A NAME:
!A
!A 	Tables: Distance Pt Pt		VARIATIONAL
!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
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Table$[256]
DIM Destination$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Format$[15]
DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

ActivateUndo
Start:!
stat= SetInputFormat("n4","")
Pick_start:E1=PickEntity("STARTING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_start
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Point1$)
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
IF NOT ValidDependency(E2) THEN Pick_end
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= ReadEntityName(E2,Point2$)
IF NOT LEN(Point2$) THEN
        Stat= AutoNameEntity(E2)
        Stat= ReadEntityName(E2,Point2$)
END IF
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)



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


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

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE ENTRY: Distance two points")
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
L1=LineTwoPoints(Ps,Pe)

V1= FreeParameter("Row",R1)
V2= FreeParameter("Column",C1)
Stat= InsertIntoTable(Table$,EntityLength(L1),Format$,V1,V2)
Stat= TableTextOrigin(Table$,V1,V2,WsRightCenter)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)

RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start


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