
! script name: move.d/dynamicmoveent
! topic: Dynamic move entity

!A
!A NAME:
!A
!A      Dynamic Move Entity
!A
!A DESCRIPTION:
!A
!A 	This script a single entity to be
!A 	moved and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT TO BE MOVED: Pick the element to be moved.
!B
!B 	REFERENCE POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point
!B 		to be used as the reference for the move.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B      PICK DESTINATION POINT : The element to be moved are displayed
!B              graphically with the cursor.
!B              Hitting the Select Buttonon the mouse will select the location.
!B              The numeric keypad controls the orientation.
!B
!B                      (6) 0   degree orientation.
!B                      (9) 45  degree orientation.
!B                      (8) 90  degree orientation.
!B                      (7) 135 degree orientation.
!B                      (4) 180 degree orientation.
!B                      (1) 225 degree orientation.
!B                      (2) 270 degree orientation.
!B                      (3) 305 degree orientation.
!B
!B              Plus (+) and (-) turn the entities +/- the angular increment.
!B              The Default angular increment is 5 degrees.
!B              Hitting ( A ) will change the increment to 10 degrees.
!B              Hitting ( a ) will change the increment to 1 degrees.
!B              Hitting ( F ) or ( f ) will change the increment to 0.1 degrees.
!B              Hitting ( D ) or ( d ) will return the increment to 5 degrees.
!B
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic move entity ")

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

Start: !
ActivateUndo
Stat=SetPickMask(WsPickAll)
Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1


stat= SetInputFormat("n4","")
	
E1= PickEntity("PICK ELEMENT TO BE MOVED")
IF ExitScript(Destination$) THEN Leave
Stat=SetInputFormat("n4"," ")

Stat=SetPickMask(WsPickNoSurf)
Pref=XyzInput("REFERENCE POINT ",WsXyzInput)
IF ExitScript(Destination$) THEN Leave

Angle= 0
PlotOff
Pdest= CopyEntity(Pref)
P1= PointXYZ(0,0,1)
Paxis= AddVectors(Pref,P1)
Stat= DeleteEntity(P1)
Axis_line= LineTwoPoints(Pref,Paxis)
Stat= DeleteEntity(Paxis)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(Pref)
PlotOn
Stat= EraseEntity(E1)

Stat=DynLabel("Rotate Angle:"&VAL$(Angle))
Vnum= LastPickView
stat= SetInputFormat("n4b","")
Rotate_angle= DynamicMoveGroup(Vnum,E1,Pref,Pdest,Angle,"PICK DESTINATION POINT")
IF ExitScript(Destination$) THEN Leave

Stat=DynLabel("")
StdWorkplane

ActivateUndo
Stat= AdvanceUndoNumber("move")
Stat= AddItemToUndo(WsUBModifyMode,E1)

Pm= SubtractVectors(Pdest,Pref)
Shift_trans=AngleTransform(Pm,0,0,0,WsWorkplaneVals)
Axis_trans= RotAboutAxisTrans(Axis_line,Rotate_angle)
Trans1=MultTransforms(Shift_trans,Axis_trans)
Stat= TransEntityTrans(E1,Trans1,1)
Stat= PlotEntity(E1)

Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
Stat= DeleteEntity(Paxis)
Stat= DeleteEntity(Axis_line)

IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

Stat=SetPickMask(WsPickAll)
GOTO Start

Leave: !
Stat=DynLabel("")
ActivateUndo
Stat=SetPickMask(WsPickAll)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
Stat= DeleteEntity(Paxis)
Stat= DeleteEntity(Axis_line)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
