
! script name: vdatatable.d/boxsizetext
! var_topic: size text entrys in a box

!A
!A NAME:
!A
!A 	Text Size    VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Size text entrys in a box.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT TEXT HEIGHT: Height of individual characters.
!B
!B 	INPUT TEXT WIDTH: Width of individual characters.
!B
!B 	INPUT TEXT SLANT: Slant angle of characters.
!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 	If the corners of a table have been locked, the sizeof the
!B 	text will not change the size of the table. Otherwise, the
!B 	table will resize itself as needed.
!B 	If the corners are locked the text entries may extend past their
!B 	entry box limits.
!B
!B 	The text size 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 command.
!B
!B      In the FreeParameters specifing Row and Column numbers.
!B      If End row is set to 0 it will default internally to the number
!B      of rows in the table.
!B      If End column is set to 0 it will default internally to the number
!B      of columns in the table.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Box size text entry ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Table$[256]
DIM Width_var$[256]
DIM Height_var$[256]
DEG

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

ActivateUndo
Text_height= GetDefault(WsTextHeight)
Text_width= GetDefault(WsTextWidth)
Start:!

Text_size:stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Text_height)
Text_height= GetValue("INPUT TEXT HEIGHT ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_height_var= LastVariableInput(Height_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Text_width)
Text_width= GetValue("INPUT TEXT WIDTH ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_width_var= LastVariableInput(width_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Slant_angle)
Slant_angle= GetValue("INPUT TEXT SLANT ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Text_slant= TAN(Slant_angle)


Element_loop:!

N1= DataTableCount
IF N1=0 THEN Leave
IF N1 > 1 THEN
Pick_table:stat= SetInputFormat("n4a1",",N,")
	Element1=PickEntity("PICK TABLE, New size ",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$= "N" THEN Start
	IF NOT ValidDependency(Element1) THEN Pick_table
        Stat= EntityNameCheck(Element1,Table$)
ELSE
	Element1= DataTableByNumber(1)
	IF NOT ValidDependency(Element1) THEN Pick_table
        Stat= EntityNameCheck(Element1,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)

IF R1> R2 THEN
        N1= R1
        R1= R2
        R2= N1
END IF
IF C1> C2 THEN
        N1= C1
        C1= C2
        C2= N1
END IF
Nrows= NumberTableRows(Element1)
Ncols= NumberTableRows(Element1)
IF R1= R2 THEN
        IF C1<>C2 AND C2= Ncols THEN C2=0
END IF
IF C1= C2 THEN
        IF R1<>R2 AND R2= Nrows THEN R2=0
END IF


ActivateUndo
Stat= AdvanceUndoNumber("size entry text")
Stat= AddItemToUndo(WsUBModifyMode,Element1)


Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Size text")
IF No_height_var THEN
	V1= FreeParameter("Text Height",Text_height)
ELSE
	V1= FreeParameter("Text Height",Height_var$)
END IF
IF No_height_var THEN
	V2= FreeParameter("Text Width",Text_width)
ELSE
	V2= FreeParameter("Text Width",Width_var$)
END IF
V3= FreeParameter("Text Slant",Text_slant)
V4= FreeParameter("Start row",R1)
V5= FreeParameter("Start column",C1)
V6= FreeParameter("End row",R2)
V7= FreeParameter("End column",C2)
Stat= TableTextSizes(Table$,V4,V5,V6,V7,V2,V1,V3)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Element1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
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
