
! script name: vdatatable.d/tlocation
! var_topic: insert the location of a point into a table

!A
!A NAME:
!A
!A 	Tables: Location	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will insert the location of a point into a table.
!A
!B INSTRUCTIONS:
!B
!B 	POINT LOCATION: Pick the point whose XYZ coordinates will
!B 		be entered into the selected table, if there are
!B 		enough columns.
!B
!B 	PICK ENTRY POSITION: Pick the row in the table for the point
!B 		location to be entered.  Note: The point information
!B 		will start in the box of the table that is selected
!B 		and will enter as much information as it can.
!B
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Table$[256]
DIM Destination$[256]
DIM Point$[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_point:E1=PickEntity("POINT LOCATION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_start
T1= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Point$)



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)
C2= C1+1
C3= C1+2

ActivateUndo
Stat= AdvanceUndoNumber("point location")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE ENTRY: point location")
SELECT Pick_return
CASE WsGeometryEnd
        Pt= ParameterReturnPt(Point$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pt= ParameterReturnPt(Point$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pt= ParameterReturnPt(Point$,T1,WsGeomCenter)
END SELECT

V1= FreeParameter("Row",R1)
V2= FreeParameter("X_column",C1)
V3= FreeParameter("Y_column",C2)
V4= FreeParameter("Z_column",C3)

Stat= InsertIntoTable(Table$,XPointValue(Pt),Format$,V1,V2)
Stat= InsertIntoTable(Table$,YPointValue(Pt),Format$,V1,V3)
Stat= InsertIntoTable(Table$,ZPointValue(Pt),Format$,V1,V4)
Stat= TableTextOrigin(Table$,V1,V2,V1,V4,WsRightCenter)
Stat= DeleteEntity(Pt)

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
