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

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

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

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Table$[256]
DIM Destination$[256]
DIM Point$[256]
DIM XYZFormat$[15]
DIM DiaFormat$[15]
DIM DepthFormat$[15]
DEG

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


A= GetDefault(WsPlacesAfter)
XYZFormat$= "decimal "&VAL$(A)
DepthFormat$= "decimal "&VAL$(A)

A= GetDefault(WsRPlacesAfter)
DiaFormat$= "decimal "&VAL$(A)


ActivateUndo
Start:!
Pick_loop:Stat=SetInputFormat("n4","")
E1=PickSpecificEnt("PICK HOLE",WsPickHoles)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
Stat= EntityNameCheck(E1,Element$)



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
C4= C1+3
C5= C1+4

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

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE ENTRY: hole location")

V1= FreeParameter("Row",R1)
V2= FreeParameter("Diameter",C1)
V3= FreeParameter("Depth",C2)
V4= FreeParameter("X_column",C3)
V5= FreeParameter("Y_column",C4)
V6= FreeParameter("Z_column",C5)
Pt= ParameterPt(Element$,0.0)
Stat= InsertIntoTable(Table$,EntityValue(Element$,WsHoleDia),DiaFormat$,V1,V2)
Stat= InsertIntoTable(Table$,EntityValue(Element$,WsHoleDepth),DepthFormat$,V1,V3)
Stat= InsertIntoTable(Table$,XPointValue(Pt),XYZFormat$,V1,V4)
Stat= InsertIntoTable(Table$,YPointValue(Pt),XYZFormat$,V1,V5)
Stat= InsertIntoTable(Table$,ZPointValue(Pt),XYZFormat$,V1,V6)

Stat= TableTextOrigin(Table$,V1,V2,V1,V6,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
