
! script name: datatable.d/tableorigin
! topic: change table origin

!A
!A NAME:
!A
!A 	Change Table Origin
!A
!A DESCRIPTION:
!A
!A 	Change Table Origin.
!A
!B INSTRUCTIONS:
!B
!B 	PICK TABLE: Pick the table you would like to modify the origin.
!B
!B 	JUSTIFY TEXT Left, Right, Center: This will place the entry to the
!B 		left,right, or center of the entry area. The individual lines
!B 		of a multiline entry are not justified.  The entire entry is
!B 		treated as a box and then justified.
!B
!B		LL LowerLeft             1
!B		ML LeftCenter            2
!B		UL UpperLeft             3
!B		LM LowerCenter           4
!B		C  CenterText            5
!B		MC UpperCenter           6
!B		UR UpperRight            7
!B		MR RightCenter           8
!B		LR LowerRight            9
!B
!B	LOCATION:  Pick the location of the table.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Table origin ")

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

stat= SetInputFormat("a2=",",UL,LL,UR,LR,C,ML,MR,UM,LM,")
Stat=SetEqualsValue(0,"UL")
Num_lines= GetValue("JUSTIFY TABLE UL, LL, UR, LR, Center ",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 "C"
        Textorig= WsCenterText
CASE "ML"
        Textorig= WsLeftCenter
CASE "MR"
        Textorig= WsRightCenter
CASE "UM"
        Textorig= WsUpperCenter
CASE "LM"
        Textorig= WsLowerCenter
END SELECT

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

ActivateUndo
Stat= AdvanceUndoNumber("move origin")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
Stat= SetTableOrigin(Element1,Pc,Textorig)
Stat= PlotEntity(Element1)
Stat= DeleteEntity(Pc)

GOTO Start

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