
! script name: move.d/movegrppic
! topic: Sample - move a group

!A
!A NAME:
!A
!A 	MOVE A GROUP
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of elements to be moved and the original
!A 	group to be deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP TO BE MOVED: Pick an element on the group to be moved. 
!B
!B 	REFERENCE POINT ON ORIGINAL ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		of the point to be used as the reference for the move.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DESTINATION POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the
!B 		destination point, which is used as the reference point
!B 		for the moved version and corresponds to the original
!B 		reference point.
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: move a group ")

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

stat= SetInputFormat("n4","")
Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

Group=CreateGroup("TEMP")


Start: !
ActivateUndo
Highlight_color= 2


    Grp1=PickGroupEnt("PICK GROUP TO BE MOVED")
    IF (ExitScript(Destination$)) THEN Leave
    Stat=AddToGroup(Group,Grp1)

Stat=Highlight(Group,Highlight_color,0)


Ps=XyzInput("REFERENCE POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Move_group:!
Pe=XyzInput("DESTINATION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

StdWorkplane

Xs=XPointValue(Ps)
Ys=YPointValue(Ps)
Zs=ZPointValue(Ps)

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

Xmove=Xe-Xs
Ymove=Ye-Ys
Zmove=Ze-Zs

Pr=PointXYZ(Xmove,Ymove,Zmove)
T1=AngleTransform(Pr,0,0,0,WsWorkplaneVals)
G1=TransformGroup(Group,T1,"TEMP1")

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

Stat=DeleteEntity(G1)
Stat=DeleteEntity(T1)
Stat=DeleteEntity(Pr)
Stat=DeleteEntity(Pe)

Stat= Unlink(Group)
Stat= DeleteGroup(Group)

IF Active_workplane THEN
	Stat=SetWorkplane(Work)
END IF

PlotAll

Leave:!
ActivateUndo
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pr)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(T1)
Stat=DeleteEntity(Group)
Stat=DeleteEntity(G1)
IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF

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

