
! script name: datatable.d/setlengthwidth
! topic: change table length and width

!A
!A NAME:
!A
!A 	Set Table Length And Width
!A
!A DESCRIPTION:
!A
!A 	This script will allow the length and width of the table to be set.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT TABLE X LENGTH: Input Table Length along the X axis.
!B
!B 	INPUT TABLE Y WIDTH: Input Table Width along the Y axis.
!B
!C NOTES:
!C
!C 	The table entries will expand or shrink proportionally to match
!C 	the table size.  An input of zero allows dynamic sizing.
!C
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Set Table Length Width ")

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

ActivateUndo
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

Xlength:!
Xlen= TableLength(Element1)
stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Xlen)
Xlen= GetValue("INPUT TABLE X LENGTH ")
IF (ExitScript(Destination$)) THEN Leave

Ywidth:!
Ywid= TableWidth(Element1)
stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Ywid)
Ywid= GetValue("INPUT TABLE Y WIDTH ")
IF (ExitScript(Destination$)) THEN Leave

S_mode=1
IF (Xlen>0) AND (Ywid = 0) THEN S_mode=2
IF (Xlen=0) AND (Ywid > 0) THEN S_mode=3

ActivateUndo
Stat= AdvanceUndoNumber("set length width")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
Stat=AutoSizeTable(Element1)
Stat= SetTableLenWidth(Element1,Xlen,Ywid,S_mode)
Stat= PlotEntity(Element1)

GOTO Start

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