
! script name: tableforms.d/columngridform
! topic: Arrange a group of tables in a grid

!A
!A NAME:
!A
!A 	Column Grid Form
!A
!A DESCRIPTION:
!A
!A	This script will allow the user to arrange a group of tables in a grid.
!A
!B INSTRUCTIONS:
!B
!B 	JUSTITY:  UL, LL, UR, LR: Enter the position to be
!B 		used to justify the tables in the grid form.
!B
!B 		UL - Upper Left
!B 		LL - Lower Left
!B 		UR - Upper Right
!B 		LR - Lower Right
!B
!B 	LOCATION X,Y,Z: Enter the X,Y,Z location of the grid form.
!B
!B 	PICK TABLE ROW # COL # : New row, Proceed: Pick the
!B 		tables to be used to form the grid.
!B
!B 		N - New row allows you to start a new row in the grid.
!B 		P - Proceed returns you to the justify question.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: arrange in a grid ")

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

DeActivateUndo
Adjust_x= WsTrue

Start:!

stat= SetInputFormat("a2=",",UL,LL,UR,LR,")
Stat=SetEqualsValue(0,"UL")
Num_lines= GetValue("JUSTITY:  UL, LL, UR, LR ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "UL"
        Textorig= WsUpperLeft
CASE "LL"
        Textorig= WsLowerLeft
CASE "UR"
        Textorig= WsUpperRight
CASE "LR"
        Textorig= WsLowerRight
CASE ELSE
        Textorig= WsUpperLeft
END SELECT

T_loc:Stat=SetInputFormat("n4","")
Pc=XyzInput("LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN T_loc


Group= CreateGroup("TABLES GRID GROUP")

New_row:!
Rung= CreateGroup("TABLES RUNG GROUP")
Stat= AddToGroup(Group,Rung)

Pick_table:!
Row_num= GroupCount(Group)
A$= "ROW #"&VAL$(Row_num)&" "

Col_num= GroupCount(Rung)
B$= "COL #"&VAL$(Col_num+1)&" "

stat= SetInputFormat("a1=",",P,N,")
Stat=SetEqualsValue(0,"N")
Table1=PickEntity("PICK TABLE "&A$&B$&":  New row, Proceed ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "P" THEN 
	Stat= TablesForm(WsColumnGridForm,Group,Pc,Textorig,Adjust_x)
	FOR I=1 TO GroupCount(Group)
		Rung= GroupElement(Group,I)
		Stat=DeleteEntity(Rung)
	NEXT I
	Stat=DeleteEntity(Group)
	Stat=DeleteEntity(Pc)
	GOTO Start
END IF
IF Answer$= "N" THEN 
	Stat= TablesForm(WsColumnGridForm,Group,Pc,Textorig,Adjust_x)
	GOTO New_row
END IF

IF NOT ValidGeometry(Table1) THEN Pick_table
Etype= EntityType(Table1)
IF Etype= WsDataTableEnt THEN
	Stat= AddToGroup(Rung,Table1)
	Stat= TablesForm(WsColumnGridForm,Group,Pc,Textorig,WsFalse)
END IF
GOTO Pick_table


Leave:!
IF ValidGeometry(Group) THEN
FOR I=1 TO GroupCount(Group)
                Rung= GroupElement(Group,I)
                Stat=DeleteEntity(Rung)
NEXT I
Stat=DeleteEntity(Group)
END IF
Stat=DeleteEntity(Pc)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
