
! script name: vcopy.d/layercopybox
! var_topic: Layer copy boxed group

!A
!A NAME:
!A
!A 	Layer Copy Box	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	copied to a layer.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		copied in.
!B
!B 	LAYER NUMBER : Enter the value for the layer where the copy is placed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: layer copy box ")

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Name$[256]
DIM Layer_var$[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

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

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: Layer copy box")
Stat= SetRecDelLastExec
G1= CreateGroup("Picked Entities")

FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Element$)
	IF ValidDependency(E1,WsFalse) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(G1,Element$)
		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$)
ActivateUndo
Stat= AdvanceUndoNumber("layer copy")
Stat= AddGroupToUndo(WsUBCreateMode,G2,2,WsTrue)
Stat= DeleteEntityList(G1,G2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= DeleteEntity(Group)

GOTO Start

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


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


