
! script name: copy.d/3dcopycontour
! topic: 3D copy group by reference points

!A
!A NAME:
!A
!A      3D Absolute Copy Group
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	copied and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP TO BE COPIED: Pick an element on the group to be copied.
!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 copy.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	DESTINATION POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point
!B 		to be used as the reference for the copied elements.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 3d absolute copy group ")

DIM Answer$[256]
DIM Destination$[256]
DIM Which$[16]
DIM Extras$[64]
DEG

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

Group=CreateGroup("TEMP")
Extras$= ""

LOOP
        stat= SetInputFormat("a1",",P,B,")
        C1=PickGroupEnt("PICK GROUP TO BE COPIED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        EXIT IF Answer$= "P"
	IF Answer$="B" THEN
		Num1=GroupCount(Group)
		C1=GroupElement(Group,Num1)
		IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
		Stat= SetSelectedFlag(C1,WsFalse)
                Stat= PlotEntity(C1)
		IF Num1=1 THEN Extras$= ""
	ELSE
		IF ValidGeometry(C1) THEN
			N1= ElementGrpNum(Group,C1)
			IF NOT N1 THEN
				Stat=AddToGroup(Group,C1)
				Stat= SetSelectedFlag(C1,WsTrue)
                		Stat= PlotEntity(C1)
			END IF
			Extras$=", Backup , Proceed "
		END IF
	END IF

END LOOP

stat= SetInputFormat("n4","")

IF NOT ValidGeometry(Group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group) THEN Start
END IF

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

Which$= "FIRST"

Dest_pt:!
FadeUndoButtons

Pe=XyzInput(Which$&" DESTINATION POINT",WsXyzInput)
IF ExitScript(Destination$) THEN Leave

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

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

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


Num1= GroupCount(Group)

ActivateUndo
Stat= AdvanceUndoNumber("copy")
FOR J= 1 TO Num1

        C1= GroupElement(Group,J)
		Pm=PointXYZ(Xmove,Ymove,Zmove)
		T1=AngleTransform(Pm,0,0,0,WsWorkplaneVals)
		PlotOff
		C2= CopyGroup(C1)
		PlotOn
		Stat=TransGroupTrans(C2,T1,0,1)
		Stat=AutoNumber(C2)
		Stat= DeleteEntity(Pm)
		Stat= SetSelectedFlag(C2,WsFalse)
                Stat= PlotEntity(C2)
		Stat= AddGroupToUndo(WsUBCreateMode,C2,1,WsTrue)
NEXT J

Stat= DeleteEntity(Pe)

Which$= "NEXT"
GOTO Dest_pt

Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pt)
Stat= DeleteEntity(Pe)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(G1)

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