
! script name: vcopy.d/rptcopyent
! var_topic: copy entity by reference points

!A
!A NAME:
!A
!A 	Absolute Copy Entity		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 ELEMENT TO BE COPIED: Pick the element to 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 entity ")

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


Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

E1= PickEntity("PICK ELEMENT TO BE COPIED",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Start
Stat=SetInputFormat("n4"," ")
Stat= EntityNameCheck(E1,Element$)
	

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)

Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: ref copy ent")
Stat= SetRecDelLastExec
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
Move_vector= VectorTwoPts(Ps,Pe)
E2= VectorCopyEntity(Element$,Move_vector)
Stat= NameEntity(E2,Name$)
Stat= DeleteEntityList(Move_vector,Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("ref copy")
Stat= AddItemToUndo(WsUBCreateMode,E2)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Ps= ParameterReturnPt(Point1$,T1,Pick_return1)

Which$= "NEXT"
GOTO Dest_pt


Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= DeleteEntityList(Move_vector,Ps,Pe)


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


