
! script name: tableinsert.d/tdiameter
! topic: insert the diameter of a circle or hole into a table

!A
!A NAME:
!A
!A 	Table: Info: Diameter
!A
!A DESCRIPTION:
!A
!A 	This script will allow the user to pick a circle or hole and the
!A 	diameter will be inserted into a table at the selected position.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CIRCLE OR HOLE: Pick the circle or hole whose diameter will
!B 		be inserted into a table at the selected position.
!B
!B 	PICK ENTRY POSITION: Pick the position in the table for the
!B 		diameter 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: diameter into table")

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

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

Start:!
ActivateUndo
Pick_loop:Stat=SetInputFormat("n4","")
E1=PickEntity("PICK CIRCLE OR HOLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
Etype= EntityType(E1)
IF Etype<>WsCircleEnt AND Etype<>WsHoleEnt THEN Pick_loop

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("diameter entry")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
IF Etype= WsCircleEnt THEN
	Stat= InsertIntoTable(Table1,(2.0*CircleRadius(E1)),Format$,R1,C1)
ELSE
	Stat= InsertIntoTable(Table1,EntityValue(E1,WsHoleDia),Format$,R1,C1)
END IF
Stat= TableTextOrigin(Table1,R1,C1,WsRightCenter)
Stat= PlotEntity(Table1)

GOTO Start

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