
! script name: tableinsert.d/ttoolloc
! topic: Sample - insert the location of a tool into a table

!A
!A NAME:
!A
!A 	Insert the location of a tool into a table
!A
!A DESCRIPTION:
!A
!A	Insert the location of a tool into a table
!A
!B INSTRUCTIONS:
!B
!B 	NO HELP AVAILABLE AT THIS TIME
!B
!B NOTES:
!B
!B 	This script is not variational. The table will not update
!B 	when the entity in changed.
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

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

DIM Answer$[256]
DIM Descr$[256]
DIM Destination$[256]
DIM XYZFormat$[15]
DIM DiaFormat$[15]
DIM DepthFormat$[15]
DIM Tool_name$[256]
DEG


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

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


Start:!
ActivateUndo
Pick_loop:Stat=SetInputFormat("n4","")
E1=PickEntity("PICK TOOL")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
Tool=GetAssocTool(E1)
IF NOT ValidGeometry(Tool) THEN Pick_loop
Stat=GetUserDataName(Tool,Tool_name$)




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

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

Stat= EraseEntity(Table1)
Pt= ParameterPt(E1,0.0)
Stat= InsertIntoTable(Table1,Tool_name$,R1,C1)
Stat= InsertIntoTable(Table1,XPointValue(Pt),XYZFormat$,R1,C2)
Stat= InsertIntoTable(Table1,YPointValue(Pt),XYZFormat$,R1,C3)
Stat= InsertIntoTable(Table1,ZPointValue(Pt),XYZFormat$,R1,C4)
Stat= TableTextOrigin(Table1,R1,C1,WsLeftCenter)
Stat= TableTextOrigin(Table1,R1,C2,R1,C4,WsRightCenter)
Stat= DeleteEntity(Pt)
Stat= PlotEntity(Table1)

GOTO Start


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