
! script name: vcopy.d/zcopybox
! var_topic: Z copy boxed group

!A
!A NAME:
!A
!A 	Z Copy Box	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	copied and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		copied in.
!B
!B 	Z INCREMENT: Value in Z to shift entities.
!B
!B 	NUMBER OF TIMES: Enter the number of times the copy process
!B 		should be repeated.
!B

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

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Name$[256]
DIM X_var$[256]
DIM Y_var$[256]
DIM Z_var$[256]
DIM Ntimes_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","")
Xmove=0
Ymove=0
Zmove=GetValue("Z INCREMENT ")
IF ExitScript(Destination$) THEN Leave
No_z_var= LastVariableInput(Z_var$)

Stat=SetInputFormat("n0=","")
Stat=SetEqualsValue(1)
Number=GetValue("NUMBER OF TIMES",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Number=0 THEN Start
No_times_var= LastVariableInput(Ntimes_var$)

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: Z copy mult ent")
Stat= SetRecDelLastExec
Egroup= 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(Egroup,Element$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn

if No_z_var THEN
	 V1= FreeParameter("Zmove",Zmove)
         Move_vector= PointXYZ(Xmove,Ymove,V1)
ELSE
         Move_vector= PointXYZ(Xmove,Ymove,Z_var$)
END IF

IF Number>1 THEN
        IF No_times_var THEN
	 	V2= FreeParameter("Number",Number)
                G1= VectorCopyGroup(Egroup,Move_vector,V2)
        ELSE
                G1= VectorCopyGroup(Egroup,Move_vector,Ntimes_var$)
        END IF
ELSE
        G1= VectorCopyGroup(Egroup,Move_vector)
END IF
Stat= AutoNameGroup(G1,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("z copy")
Stat= AddGroupToUndo(WsUBCreateMode,G1,2,WsTrue)
Stat= DeleteSubGroups(G1)
Stat= DeleteEntityList(Egroup,Move_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

GOTO Start

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


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


