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

!A
!A NAME:
!A
!A 	Tables: Diameter	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will insert the diameter of a circle or hole into
!A 	a selected position in a table.
!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
!# see also - htdocs/help.d/datatables.htm

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

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

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

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


ActivateUndo
Start:!
Pick_loop:Stat=SetInputFormat("n4","")
E1=PickEntity("PICK CIRCLE OR HOLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
Stat= EntityNameCheck(E1,Element$)
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 ValidDependency(Table1) THEN Pick_entry
T1= LastPickPara
Stat= EntityNameCheck(Table1,Table$)
R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)

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

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

V1= FreeParameter("Row",R1)
V2= FreeParameter("Column",C1)
RecordFunctionOff
IF Etype= WsCircleEnt THEN
RecordFunctionOn
Stat= InsertIntoTable(Table$,(2.0*CircleRadius(Element$)),Format$,V1,V2)
RecordFunctionOff
ELSE
RecordFunctionOn
Stat= InsertIntoTable(Table$,EntityValue(Element$,WsHoleDia),Format$,V1,V2)
RecordFunctionOff
END IF
RecordFunctionOn
Stat= TableTextOrigin(Table$,V1,V2,WsRightCenter)

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
