
! script name: copy.d/dmultcopycont
! topic: dynamic copy multiple groups

!A
!A NAME:
!A
!A      Dynamic Copy Multiple Groups
!A
!A DESCRIPTION:
!A
!A 	This script copies multiple groups graphically.
!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 	PICK DESTINATION POINT : The elements to be copied are displayed
!B 		graphically with the cursor.
!B
!B 		Hitting the Select Button on the mouse will select the location.
!B 		The numeric keypad controls the orientation.
!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 		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
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic multiple copy ")

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

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

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

stat= SetInputFormat("n4","")
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 
		Stat= DeleteEntity(Group)
		GOTO Start
	END IF
END IF


Pref=XyzInput("REFERENCE POINT ",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
P1= PointXYZ(0,0,1)
Paxis= AddVectors(Pref,P1)
Stat= DeleteEntity(P1)
Axis_line= LineTwoPoints(Pref,Paxis)

Stat= SetSelectedFlag(Group,WsFalse)
Stat=PlotEntity(Group)

Place_group:!
FadeUndoButtons
Angle= 0
Pdest= CopyEntity(Pref)

Num1= GroupCount(Group)
Group1= CreateGroup("TEMP")
FOR I= 1 TO Num1
	G1= GroupElement(Group,I)
	G2= CopyGroup(G1)
	Stat= AddToGroup(Group1,G2)
NEXT I

Vnum= LastPickView
Erase_original= WsFalse
stat= SetInputFormat("n4b","")
Rotate_angle= DynamicMoveGroup(Vnum,Group1,Pref,Pdest,Angle,"PICK DESTINATION POINT",Erase_original)
IF ExitScript(Destination$) THEN 
	Stat= DeleteGroup(Group1,WsTrue,WsTrue)
	GOTO Leave
END IF

StdWorkplane
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)
Num1=GroupCount(Group1)
ActivateUndo
Stat= AdvanceUndoNumber("copy")
FOR I= 1 TO Num1
	G1= GroupElement(Group1,I)
	Stat=TransGroupTrans(G1,Trans1)
	Stat= SetSelectedFlag(G1,WsFalse)
	Stat= AutoNumber(G1)
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
NEXT I
Stat= DeleteEntity(Group1)

Stat= DeleteEntity(Pm)
Stat= DeleteEntity(Pdest)

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

GOTO Place_group

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

stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(Group1)
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
