
! script name: vcopy.d/layercopymulti
! var_topic: layer copy picked group by incremental moves

!A
!A NAME:
!A
!A 	Layer Copy Picked Group
!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 ELEMENTS 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 picked group ")
DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DIM Element$[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: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

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

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

FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Element$)
	IF ValidDependency(E1) 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= 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



