
! script name: vcopy.d/3dinccopyent
! var_topic: 3D copy entity by incremental moves

!A
!A NAME:
!A
!A 	3D Incremental Copy Entity	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 	PICK ELEMENT TO BE COPIED: Pick the element to be copied.
!B
!B 	X,Y,Z INCREMENT: Enter the value in X,Y,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: 3d incremental copy entity ")
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","")
	
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=","")
stat= SetEqualsValue(Xmove)
Xmove=GetValue("X INCREMENT ")
IF ExitScript(Destination$) THEN Leave
No_x_var= LastVariableInput(X_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Ymove)
Ymove=GetValue("Y INCREMENT ")
IF ExitScript(Destination$) THEN Leave
No_y_var= LastVariableInput(Y_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Zmove)
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$)


Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("COPY: 3d copy ent")
Stat= SetRecDelLastExec
IF No_x_var THEN
	V1= FreeParameter("Xmove",Xmove)
        IF No_y_var THEN
		V2= FreeParameter("Ymove",Ymove)
                if No_z_var THEN
			V3= FreeParameter("Zmove",Zmove)
                        Move_vector= PointXYZ(V1,V2,V3)
                ELSE
                        Move_vector= PointXYZ(V1,V2,Z_var$)
                END IF
        ELSE
                if No_z_var THEN
			V3= FreeParameter("Zmove",Zmove)
                        Move_vector= PointXYZ(V1,Y_var$,V3)
                ELSE
                        Move_vector= PointXYZ(V1,Y_var$,Z_var$)
                END IF
        END IF
ELSE
        IF No_y_var THEN
		V2= FreeParameter("Ymove",Ymove)
                if No_z_var THEN
			V3= FreeParameter("Zmove",Zmove)
                        Move_vector= PointXYZ(X_var$,V2,V3)
                ELSE
                        Move_vector= PointXYZ(X_var$,V2,Z_var$)
                END IF
        ELSE
                if No_z_var THEN
			V3= FreeParameter("Zmove",Zmove)
                        Move_vector= PointXYZ(X_var$,Y_var$,V3)
                ELSE
                        Move_vector= PointXYZ(X_var$,Y_var$,Z_var$)
                END IF
        END IF
END IF
IF Number>1 THEN
	IF No_times_var THEN
		V4= FreeParameter("Number",Number)
		E2= VectorCopyEntity(Element$,Move_vector,V4)
	ELSE
		E2= VectorCopyEntity(Element$,Move_vector,Ntimes_var$)
	END IF
	Stat= AutoNameGroup(E2,Name$)

	ActivateUndo
	Stat= AdvanceUndoNumber("3d copy")
	Stat= AddGroupToUndo(WsUBCreateMode,E2,0,WsTrue)
	Stat= DeleteEntity(E2)

ELSE
	E2= VectorCopyEntity(Element$,Move_vector)
	Stat= NameEntity(E2,Name$)

	ActivateUndo
	Stat= AdvanceUndoNumber("3d copy")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)

END IF
Stat= DeleteEntity(Move_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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


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

