
! script name: vcopy.d/2drptcopymult
! var_topic: 2D copy picked group by reference points

!A
!A NAME:
!A
!A     2D  Absolute Copy Picked Group	VARIATIONAL
!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 ELEMENTS TO BE COPIED, PROCEED: Pick one of the elements to be
!B 		copied.  The question will repeat until "PROCEED" is answered.
!B 		All elements picked will then be copied.
!B
!B 	REFERENCE POINT: Pick the point to be used as the reference for
!B 		the copy.
!B
!B 	DESTINATION POINT: Pick the point to be used as the destination
!B 		for the copy.
!B

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

DIM Answer$[256]
DIM Destination$[256]
DIM Which$[16]
DIM Extras$[64]
DIM Element$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DEG


Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

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

LOOP
	Stat= SetInputFormat("a1",",P,B,")
Pick_ent:E1= PickEntity("PICK ELEMENTS TO BE COPIED"&Extras$,Answer$)
        IF ExitScript(Destination$) THEN Leave
	Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
	IF Answer$="B" THEN
		Num1=GroupCount(Group)
		E1=GroupElement(Group,Num1)
		IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
		Stat= SetSelectedFlag(E1,WsFalse)
		Stat= PlotEntity(E1)
		IF Num1=1 THEN Extras$= ""
	ELSE
		IF ValidGeometry(E1) THEN
		IF NOT ValidDependency(E1) THEN Pick_ent
			N1= ElementGrpNum(Group,E1)
			IF NOT N1 THEN Stat=AddToGroup(Group,E1)
			Extras$=", Backup , Proceed "
			Stat= SetSelectedFlag(E1,WsTrue)
			Stat= PlotEntity(E1)
		END IF
	END IF
END LOOP

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

Ref_pt:P1=PickEntity("REFERENCE POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P1) THEN Ref_pt
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(P1,Point1$)
Ps= ParameterReturnPt(P1,T1,Pick_return1)

Which$= "FIRST"

Dest_pt:!
FadeUndoButtons
Stat=SetLastPoint(Ps)
P2=PickEntity(Which$&"  DESTINATION POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P2) THEN Dest_pt
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(P2,Point2$)
Pe= ParameterReturnPt(P2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)


Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: ref copy multi ent")
Stat= SetRecDelLastExec
Egroup= CreateGroup("Picked Entities")
FOR I=1 TO Num_elements
RecordFunctionOff
	E1= GroupElement(Group,I)
	Stat= ReadEntityName(E1,Element$)
	IF NOT LEN(Element$) THEN
                Stat= AutoNameEntity(E1)
                Stat= ReadEntityName(E1,Element$)
        END IF
	IF ValidDependency(E1) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(Egroup,Element$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
Ps1= ProjectEntity(Ps,0.0)
Pe1= ProjectEntity(Pe,0.0)
Move_vector= VectorTwoPts(Ps1,Pe1)
G1= VectorCopyGroup(Egroup,Move_vector)
Stat= AutoNameGroup(G1,Name$)
RecordFunctionOff
Stat= SetSelectedFlag(G1,WsFalse)
ActivateUndo
Stat= AdvanceUndoNumber("ref copy multi")
Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsTrue)
RecordFunctionOn
Stat= DeleteEntityList(G1,Egroup,Move_vector,Ps,Pe,Ps1,Pe1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Ps= ParameterReturnPt(Point1$,T1,Pick_return1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Which$= "NEXT"
GOTO Dest_pt


Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntityList(Group,G1,Move_vector,Ps,Pe)


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

