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

!A
!A NAME:
!A
!A     Point Group Copy Multiple Entities	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows multiple entities to be copied.
!A	The locations specified by a group of points.
!A
!B INSTRUCTIONS:
!B
!B	PICK ENTITIES TO BE COPIED, PROCEED: Pick one of the entities 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	PICK GROUP OF DESTINATION POINTS: Pick the group of points
!B		for the copy.
!B

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

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


Dest_pt:!
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)
Stat= SetSelectedFlag(Group,WsFalse)


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= SetSelectedFlag(Group,WsFalse)
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

