
! script name: vcopy.d/ptgrpcopybox
! var_topic: copy entities by group of points

!A
!A NAME:
!A
!A     Point Group Copy Box   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	copied to the locations of a point group.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		copied in.
!B
!B 	REFERENCE POINT: Pick the point to be used as the reference for 
!B 		the copy.
!B
!B	PICK GROUP OF DESTINATION POINTS: Pick the group of points
!B		for the copy.
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: point group contour ")

DIM Answer$[256]
DIM Destination$[256]
DIM Which$[16]
DIM Contour$[256]
DIM Pgroup$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Extras$[256]
DEG


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

stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")
Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF ExitScript(Destination$) THEN Leave

FadeUndoButtons
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)


Dest_pt:!
FadeUndoButtons
Stat=SetLastPoint(Ps)
Pgroup=PickGroupEnt("PICK GROUP OF DESTINATION POINTS")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Pgroup) THEN Start
Stat= EntityNameCheck(Pgroup,Pgroup$)
Stat=Highlight(Pgroup,Highlight_color,WsDirArrowOff)
IF NOT ValidGeometry(Pgroup) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Pgroup) THEN Dest_pt
END IF
Stat= DeleteEntity(Ps)


Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: pt group copy entities")
Stat= SetRecDelLastExec
G1= CreateGroup("Picked Entities")
FOR I=1 TO Num_elements
RecordFunctionOff
        Contour= GroupElement(Group,I)
        Stat= EntityNameCheck(Contour,Contour$)
        IF ValidDependency(Contour) THEN
                RecordFunctionOn
                Stat= AddToGroup(G1,Contour$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
Stat= NullReference(Pgroup$)
SELECT Pick_return1
CASE WsGeometryEnd
        Pref= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pref= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pref= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
G2= PtGroupCopyGroup(G1,Pref,Pgroup$)
Stat= AutoNameGroup(G2,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("pt group copy")
Stat= AddGroupToUndo(WsUBCreateMode,G2,2,WsTrue)
Stat= DeleteSubGroups(G2)
Stat= DeleteEntityList(G1,Pref)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(Ps)
GOTO Start

Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Group)

IF (NOT LEN(Destination$)) THEN
         LOAD "typecontrol"
ELSE
        IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
         LOAD Destination$
END IF
END

