
! script name: vcopy.d/layercopyent
! var_topic: Sample - Layer copy entity

!A
!A NAME:
!A
!A 	Layer Copy Entity   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 	PICK ELEMENT TO BE COPIED: Pick the element to be copied.
!B
!B 	LAYER NUMBER: Enter the value for the layer where the copy is placed.
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: layer copy entity ")
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","")
	
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$)

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

Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: Layer copy ent")
Stat= SetRecDelLastExec
E2= CopyEntity(Element$)
Stat= NameEntity(E2,Name$)
IF No_layer_var THEN
	V1= FreeParameter("Layer",Layer)
	Stat= SetLayer(E2,V1)
ELSE
	Stat= SetLayer(E2,Layer_var$)
END IF
Stat= DeleteEntity(Move_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("layer copy")
Stat= AddItemToUndo(WsUBCreateMode,E2)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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


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

