
! script name: move.d/worktowork
! topic: workplane to workplane move

!A
!A NAME:
!A
!A 	Workplane To Workplane Move
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities to have their data transformed
!A 	from the current workplane to another workplane.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY FOR ORIGINAL WORKPLANE: Pick an entity on the original workplane.
!B
!B 	PICK ENTITY FOR DESTINATION WORKPLANE: Pick an entity on the workplane
!B 		that is the destination of the group of entities to be transformed.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Select the view containing the entities.
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner of the box.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other corner of the view box.
!B
!B 	REFERENCE POINT ON ORIGINAL ABS X,Y,Z: Enter the X,Y,Z coordinates of
!B 		the point on the original workplane to be used as the
!B 		reference for the group to be transformed.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DESTINATION POINT ON COPY ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		to be used as the reference for the destination of the
!B 		transformed group.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: workplane to workplane move ")

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

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


StdWorkplane
Origin_ent=PickEntity("PICK ENTITY FOR ORIGINAL WORKPLANE")
IF (ExitScript(Destination$)) THEN Leave

Origin_plane=GetTransform(Origin_ent)
IF ValidGeometry(Origin_plane) THEN
	Delete_trans1=0
ELSE
	Pr=PointXYZ(0,0,0)
	Origin_plane=AngleTransform(Pr,0,0,0)
	Delete_trans1=1
	Stat=DeleteEntity(Pr)
END IF

Dest_ent=PickEntity("PICK ENTITY FOR DESTINATION WORKPLANE")
IF (ExitScript(Destination$)) THEN Leave

Dest_plane=GetTransform(Dest_ent)
IF ValidGeometry(Dest_plane) THEN
	Delete_trans2=0
ELSE
	Pr=PointXYZ(0,0,0)
	Dest_plane=AngleTransform(Pr,0,0,0)
	Delete_trans2=1
	Stat=DeleteEntity(Pr)
END IF

StdWorkplane
Group=CreateGroup("TEMP")

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

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

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

Pe=XyzInput("DESTINATION POINT ON COPY(real coordinates)  ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetWorkplane(Origin_plane)

X=-XPointValue(Ps)
Y=-YPointValue(Ps)
Z=-ZPointValue(Ps)
StdWorkplane
Ps1=PointXYZ(X,Y,Z)
Tshift1=AngleTransform(Ps1,0,0,0)

Inv_work=InverseTrans(Origin_plane)

Stat=SetWorkplane(Dest_plane)

X=XPointValue(Pe)
Y=YPointValue(Pe)
Z=ZPointValue(Pe)
StdWorkplane
Pe1=PointXYZ(X,Y,Z)
Tshift2=AngleTransform(Pe1,0,0,0)

T2=MultTransforms(Tshift1,Inv_work)
T3=MultTransforms(Tshift2,T2)
T4=MultTransforms(Dest_plane,T3)

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

Stat=TransGroupTrans(Group,T4)
Stat=Unlink(Group)
Stat= DeleteEntity(Group)

Leave:!
ActivateUndo
IF Active_workplane THEN
	Stat=SetWorkplane(Current_work)
ELSE
	StdWorkplane
END IF
stat= SetInputFormat("n4","")
Stat=DeleteEntity(G1)
Stat=DeleteEntity(Pr)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Ps1)
Stat=DeleteEntity(Pe1)
Stat=DeleteEntity(T2)
Stat=DeleteEntity(T3)
Stat=DeleteEntity(Inv_work)
Stat=DeleteEntity(Tshift1)
Stat=DeleteEntity(Tshift2)
IF Delete_trans1 THEN
	Stat=DeleteEntity(Origin_plane)
END IF
IF Delete_trans2 THEN
	Stat=DeleteEntity(Dest_plane)
END IF
PlotAll
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END




