
! script name: vtableforms.d/arrangecol
! var_topic: Arrange a group of tables in a column

!A
!A NAME:
!A
!A 	Column Form
!A
!A DESCRIPTION:
!A
!A	This script will allow the user to arrange a group of tables
!A 	in a column.
!A
!B INSTRUCTIONS:
!B
!B 	JUSTITY:  UL, LL, UR, LR: Enter the position to be used to justify
!B 		the tables in the 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.
!B
!B 	PICK TABLE #, Proceed: Select the tables to arrange in the column form.
!B 		Proceed will take you back to the JUSTIFY question, to start
!B 		a new column form.
!B

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

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

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Adjust_x= WsTrue

ActivateUndo
Start:!

stat= SetInputFormat("a2=",",UL,LL,UR,LR,")
Stat=SetEqualsValue(0,"UL")
Stat= 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","")
E1=PickEntity("LOCATION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN T_loc
Stat= EntityNameCheck(E1,Point$)
Para1= LastPickPara
Pick_return1= CurrPickReturn

Group1= CreateGroup("TABLES")
Pick_table:!
Tcount= GroupCount(Group1)
IF Tcount=0 THEN
	A$=""
ELSE
	A$= " #"&VAL$(Tcount+1)&" "
END IF
stat= SetInputFormat("a1",",P,")
Table1=PickEntity("PICK TABLE"&A$&":  Proceed ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "P" THEN Make_record

IF NOT ValidDependency(Table1) THEN Pick_table
Stat= EntityNameCheck(Table1,Table$)
Etype= EntityType(Table1)
IF Etype= WsDataTableEnt THEN
	Stat= AddToGroup(Group1,Table1)
END IF
GOTO Pick_table

Make_record:!
Num_elements= GroupCount(Group1)
IF Num_elements<2 THEN Start

ActivateUndo
Stat= AdvanceUndoNumber("column form")
Stat= AddGroupToUndo(WsUBModifyMode,Group1,0,WsFalse)

RecordFunctionOn
Stat= RecordDescr("TABLE: Arrange column form")
G1= CreateGroup("")
RecordFunctionOff
FOR I= 1 TO Num_elements
        E1= GroupElement(Group1,I)
        IF ValidGeometry(E1) THEN
                Stat= EntityNameCheck(E1,Answer$)
                RecordFunctionOn
                Stat= AddToGroup(G1,Answer$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,Para1,WsGeomCenter)
END SELECT
V1= FreeParameter("Origin",Textorig)
V2= FreeParameter("Adjust_x",Adjust_x)
Stat= TablesForm(WsColumnForm,G1,Pc,V1,V2)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= DeleteEntity(Group1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Pick_table


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