
! script name: vcopy.d/layercopymcont
! var_topic: copy multiple contours to a new layer

!A
!A NAME:
!A
!A 	Layer Copy Multiple Contours
!A
!A DESCRIPTION:
!A
!A 	This script allows multiple contours to be 
!A 	copied to a layer.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOURS 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 	LAYER NUMBER: Enter the value for the layer where the copy is placed.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: layer copy multiple contours ")
DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DIM Contour$[256]
DIM Name$[256]
DIM Layer_var$[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:Contour= PickGroupEnt("PICK CONTOURS TO BE COPIED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        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(Contour) THEN
                IF NOT ValidDependency(Contour) THEN Pick_ent
                        N1= ElementGrpNum(Group,Contour)
                        IF NOT N1 THEN Stat=AddToGroup(Group,Contour)
                        Extras$=", Backup , Proceed "
                        Stat= SetSelectedFlag(Contour,WsTrue)
                        Stat= PlotEntity(Contour)
                END IF
        END IF
END LOOP
IF NOT ValidGeometry(Group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group) THEN Start
END IF

stat= SetInputFormat("n4","")
Layer=InputLayer("LAYER NUMBER ")
IF ExitScript(Destination$) THEN Leave
No_layer_var= LastVariableInput(Layer_var$)

Make_record:!
Stat= SetSelectedFlag(Group,WsFalse)
Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: Layer copy mult cont")
Stat= SetRecDelLastExec
G1= CreateGroup("Picked Contours")
FOR I=1 TO Num_elements
	RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Contour$)
	IF ValidDependency(E1) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(G1,Contour$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
G2= CopyGroup(G1)
IF No_layer_var THEN
	V1= FreeParameter("Layer",Layer)
	Stat= SetLayer(G2,V1)
ELSE
	Stat= SetLayer(G2,Layer_var$)
END IF
Stat= AutoNameGroup(G2,Name$)
Stat= SetNoPathFlag(G2,WsTrue)
ActivateUndo
Stat= AdvanceUndoNumber("layer copy")
Stat= AddGroupToUndo(WsUBCreateMode,G2,0,WsTrue)
Stat= DeleteEntityList(G1,G2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

Leave: !
ActivateUndo
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)


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



