
! script name: move.d/movedelete
! topic: Sample - move group of elements and delete original

!A
!A NAME:
!A
!A 	Move 2D
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of elements to be moved and the original
!A 	group to be deleted.  The elements may be moved in one of three ways:
!A
!A 		1) SELECTION BOX
!A 		2) PICK INDIVIDUAL ELEMENTS
!A 		3) PICK A GROUP
!A
!A 	The mode may be changed by editing the named variable "pick type'.
!A 	To edit a named variable select the "EDIT USER DATA" option in the
!A 	"Edit" subdirectory, then select the "NAMED VARIABLES" option.  The
!A 	variable "pick type" should be one of the choices.  ( The numbers
!A	above are the ones associated with the variable. )
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		moved in.  This question is for SELECTION BOX mode only.
!B
!B 	PICK ELEMENT, PROCEED: Pick one of the elements to be moved.  This
!B 		question is for PICK INDIVIDUAL ELEMENTS mode only.  The
!B 		question will repeat until "PROCEED" is answered.  All
!B 		elements picked will then be moved and the original elements
!B 		deleted.
!B
!B 	PICK GROUP TO BE MOVED: Pick an element on the group to be moved.
!B 		This question is for a PICK A GROUP mode only.
!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 	A contour that has been created using type numbers should be unlinked
!C 	before it is moved.  The auto link feature should be used after the
!C 	move is completed.
!C
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: move and delete original ")

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")

Pick_type=NamedVarVal("pick type",WsSystemVars,2.0)

Start: !
ActivateUndo

SELECT Pick_type

  CASE 1    ! PICK BOX

    Vnum=PickView("SELECT VIEW FOR SELECTION BOX")
    IF (ExitScript(Destination$)) THEN Leave

    Stat=PickBox(Group,Vnum,WsPickPen)
    IF (ExitScript(Destination$)) THEN Leave

  CASE 2    ! PICK ELEMENTS

    LOOP
      Stat=SetInputFormat("a7",",PROCEED,")
      E1= PickEntity("PICK ELEMENTS, PROCEED",Answer$)
      IF (ExitScript(Destination$)) THEN Leave
      Stat=SetInputFormat("n4"," ")
    EXIT IF Answer$="PROCEED"
      Stat=AddToGroup(Group,E1)
    END LOOP

  CASE 3    ! PICK GROUP

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

  CASE ELSE

    Pick_type=1
    GOTO Start

END SELECT

FadeUndoButtons
Ps=XyzInput("REFERENCE POINT ON ORIGINAL",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(WsUBCreateMode,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

