
! script name: vdatatable.d/tableorigin
! var_topic: change table origin.

!A
!A NAME:
!A
!A 	Tables: Origin		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Change Table Origin.
!A
!B INSTRUCTIONS:
!B
!B 	JUSTIFY TEXT Left, Right, Center: This will place the entry to
!B 		the left,right, or center of the entry area. The
!B 		individual lines of a multiline entry are not justified.
!B 		The entire entry is 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
!# see also - htdocs/help.d/datatables.htm

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

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

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
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 ValidDependency(Element1) THEN Element_loop
	Stat= EntityNameCheck(Element1,Table$)
ELSE
        Element1= DataTableByNumber(1)
	IF NOT ValidDependency(Element1) THEN Element_loop
	Stat= EntityNameCheck(Element1,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","")
E1=PickEntity("LOCATION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Center_point
Stat= EntityNameCheck(E1,Point$)
T1= LastPickPara
Pick_return1= CurrPickReturn
Pc= ParameterReturnPt(E1,T1,Pick_return1)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)


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

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Origin")
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,T1,WsGeomCenter)
END SELECT
V1= FreeParameter("Text_orig",Textorig)
Stat= SetTableOrigin(Table$,Pc,V1)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Element1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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