
! script name: rims.d/workcopycontour
! topic: workplane copy contour

!A
!A NAME:
!A
!A 	Workplane Copy
!A
!A DESCRIPTION:
!A
!A 	This script copies a contour from a workplane to the current workplane.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY FOR ORIGINAL WORKPLANE: Pick an entity on the original
!B 		workplane.
!B
!B	PICK CONTOUR:
!B
!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 copy ")

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

ActivateUndo
stat= SetInputFormat("n4","")
Active_workplane=0
Current_work=CurrentWorkplane
Dest_plane= 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
ELSE
	Pr=PointXYZ(0,0,0)
	Origin_plane=AngleTransform(Pr,0,0,0)
	Stat=DeleteEntity(Pr)
END IF

IF NOT ValidGeometry(Dest_plane) THEN
	Pr=PointXYZ(0,0,0)
	Dest_plane=AngleTransform(Pr,0,0,0)
	Stat=DeleteEntity(Pr)
END IF

StdWorkplane

Contour=PickGroupEnt("PICK CONTOUR TO BE COPIED ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Contour) THEN Start
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

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)

Contour2= CopyGroup(Contour)
PlotOn
Stat=TransGroupTrans(Contour2,T4,0,1)
Stat=AutoNumber(Contour2)

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)

ActivateUndo
Stat= AdvanceUndoNumber("copy")
Stat= AddGroupToUndo(WsUBCreateMode,Contour2,1,WsTrue)

Leave:!
ActivateUndo
IF Active_workplane THEN
	Stat=SetWorkplane(Current_work)
ELSE
	StdWorkplane
END IF
stat= SetInputFormat("n4","")
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)
PlotAll
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END




