
! script name: datatable.d/boxformat
! topic: format numeric entries in a box

!A
!A NAME:
!A
!A 	Numeric Format
!A
!A DESCRIPTION:
!A
!A 	Format numeric entries in a box.
!A
!B INSTRUCTIONS:
!B
!B 	ENTRY TYPE: Numeric, Diameter, Angle, $: Specify the type of
!B 		numeric entry.
!B
!B 		N - Numeric is a plain decimal.
!B 		F - Free Format prints full precision.
!B 		D - Diameter uses the diameter symbol as a prefix.
!B 		A - Angle uses the deg sign.
!B 		$ is money in US dollars.
!B
!B 	PLACES AFTER: Enter the number of
!B 		places after the decimal point.
!B
!B 	PICK TABLE: Pick the table to be modified.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick window
!B 		view for selection.
!B
!B NOTES:
!B
!B 	Tables do not round numeric entries.
!B
!B 	The value of the numeric entry in a table is unaffected by
!B 	the format. If the value is a computed number it will retain
!B 	the accuracy that was originally specified.
!B
!B 	The format of all entries selected will be changed.
!B 	Make sure the selection box is contained within the
!B 	table. Selecting outside the table will cancel the
!B 	command.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Format entries ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DEG


ActivateUndo
Start:!
stat= SetInputFormat("a1=",",D,F,N,A,$,")
Stat= SetEqualsValue(0,"N")
stat= GetValue("ENTRY TYPE:  Numeric, Diameter, Angle, $ ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "N"
        Format$="decimal"
        places_after= 4
CASE "F"
        Format$="noformat"
        places_after= 4
CASE "A"
        Format$="degrees"
        places_after= 3
CASE "D"
        Format$="diameter"
        places_after= 4
CASE "$"
        Format$="$"
        places_after= 2
END SELECT
IF Format$<> "noformat" THEN
        stat= SetInputFormat("n0=","")
        Stat= SetEqualsValue(places_after)
        Places_after= GetValue("PLACES AFTER ")
        IF (ExitScript(Destination$)) THEN Leave

        IF Places_after=0 AND Format$<> "dollars" THEN
                Format$= "integer"
        ELSE
                Format$= Format$&" "&VAL$(Places_after)
        END IF
END IF


Element_loop:!
N1= DataTableCount
IF N1=0 THEN Leave
IF N1 > 1 THEN
Pick_table:stat= SetInputFormat("n4a1",",N,")
        Element1=PickEntity("PICK TABLE, New format ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "N" THEN Start
        IF NOT  ValidGeometry(Element1) THEN Pick_table
ELSE
        Element1= DataTableByNumber(1)
        IF NOT  ValidGeometry(Element1) THEN Pick_table
END IF


Pick_loop:!
Vnum= LastPickView
L1=WorkplaneBox(Vnum)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(L1) THEN Pick_loop

Len1= LineLength(L1)
IF Len1< 0.0001 THEN
        Stat= DeleteEntity(L1)
        GOTO Start
END IF

Pt1= ParameterPt(L1,0.0)
T1= ParameterInTable(Element1,Pt1)
Stat= DeleteEntity(Pt1)
IF T1 <= 0 THEN Pick_loop
R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Pt2= ParameterPt(L1,1.0)
T2= ParameterInTable(Element1,Pt2)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(L1)
IF T2 <= 0 THEN Pick_loop
R2=TableParaRow(Element1,T2)
C2=TableParaColumn(Element1,T2)

ActivateUndo
Stat= AdvanceUndoNumber("format entries")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
Stat= ChangeTableFormats(Element1,R1,C1,R2,C2,Format$)
Stat= PlotEntity(Element1)

GOTO Pick_loop

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