
! script name: move.d/2dmovemulti
! topic: 2D move element(s) by reference points

!A
!A NAME:
!A
!A 	2D Reference
!A
!A DESCRIPTION:
!A
!A 	This script allows elements or a single element to be moved.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENTS TO BE MOVED, Backup, Proceed: Pick
!B 		one of the elements to be moved.  The question will
!B 		repeat until "Proceed" is answered.  All elements
!B 		picked will then be moved.
!B
!B 	REFERENCE POINT ABS X,Y: Enter the X,Y
!B 		coordinates of the point to be used as the reference
!B 		for the move.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DESTINATION POINT ABS X,Y: Enter the X,Y
!B 		coordinates of the point to be used as the reference
!B 		for the moved elements.  NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 2D Reference")

DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DEG

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")
Extras$= ""

LOOP
        stat= SetInputFormat("a1",",P,B,")
        E1= PickEntity("PICK ELEMENTS TO BE MOVED"&Extras$,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                E1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
		Stat= SetSelectedFlag(E1,WsFalse)
                Stat= PlotEntity(E1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(E1) THEN
                        N1= ElementGrpNum(Group,E1)
                        IF NOT N1 THEN Stat=AddToGroup(Group,E1)
                        Extras$=", Backup , Proceed "
			Stat= SetSelectedFlag(E1,WsTrue)
                	Stat= PlotEntity(E1)
                END IF
        END IF

END LOOP

IF NOT ValidGeometry(Group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group) THEN Start
END IF

Pt=XyzInput("REFERENCE POINT ",WsXyOnly)
IF ExitScript(Destination$) THEN Leave

Pe=XyzInput("DESTINATION POINT",WsXyInput)
IF ExitScript(Destination$) THEN Leave

Xs=XPointValue(Pt)
Ys=YPointValue(Pt)

Xe=XPointValue(Pe)
Ye=YPointValue(Pe)

Xmove=Xe-Xs
Ymove=Ye-Ys
Zmove= 0

Stat= SetSelectedFlag(Group,WsFalse)
Stat= EraseEntity(Group)

ActivateUndo
Stat= AdvanceUndoNumber("move")
Stat= AddGroupToUndo(WsUBModifyMode,Group,2,WsTrue)

Pm=PointXYZ(Xmove,Ymove,Zmove)
T1=AngleTransform(Pm,0,0,0,WsWorkplaneVals)
Stat=TransGroupTrans(Group,T1,0,1)

Stat= PlotEntity(Group)
Stat=Unlink(Group)
Stat=DeleteEntity(Group)

Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pt)
Stat= DeleteEntity(Pe)

GOTO Start

Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pt)
Stat= DeleteEntity(Pe)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
