
! script name: datatable.d/boxcolor
! topic: color entries in a box

!A
!A NAME:
!A
!A 	Text Color
!A
!A DESCRIPTION:
!A
!A 	Color entries in a box.
!A
!B INSTRUCTIONS:
!B
!B 	PICK TABLE: Pick the table to be modified.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick window view for selection.
!B
!B NOTES: 
!B
!B 	The colors of all entries selected will be changed.  Make sure the
!B 	selection box is contained within the table. Selecting outside the
!B 	table will cancel the command.
!B
!# see also - htdocs/help.d/datatables.htm

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

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

ActivateUndo
Pen_color= CurrentColor
RaiseColorBox

Start:!


Element_loop:!
N1= DataTableCount
IF N1=0 THEN Leave
IF N1 > 1 THEN
Pick_table:stat= SetInputFormat("n4","")
        Element1=PickEntity("PICK TABLE")
        IF (ExitScript(Destination$)) THEN Leave
        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("color entries")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Color1= CurrentColor
Stat= SetTableColors(Element1,R1,C1,R2,C2,Color1)
Stat= PlotDataTable(Element1,R1,C1,R2,C2,0)

GOTO Pick_loop

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