
! script name: vdelete.d/delprefixvars
! var_topic: delete variational variables by prefix.

!A
!A NAME:
!A
!A 	Delete Variational Variables By Prefix.
!A
!A DESCRIPTION:
!A
!A 	This script deletes variational variables which have a given prefix.
!A	This script will not delete any variables which are referenced.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE PREFIX: Enter the prefix of the variables to be deleted.
!B
!B
!B NOTES:
!B
!B	Strategies or Hole Features create variables with names that are
!B	prefixed with identifiers such as O1_vs1_. If the records brought in
!B	by the strategy are deleted the variables remain. This script may
!B	be used to clean up those variables.
!B	

Stat=ChangeLabelStr("ScriptNameStatus","Function: delete variables by prefix")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Prefix$[256]
DIM Vname$[256]
DIM File$[256]

Lf$= CHR$(10)
File$= "tempdata"
Start:!

DeActivateUndo
Stat=SetInputFormat("a99","")
Stat=GetValue("VARIABLE PREFIX",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Leave
Prefix$= MakeNameValid(Answer$,WsValidVarName)

Stat= OutputString(File$,"      VARIABLES DELETED     "&Lf$,WsNewFile)
Stat= OutputString(File$,Lf$,WsAppend)
Vgroup= GrpByEntType(WsNamedVarEnt)
IF NOT ValidGeometry(Vgroup) THEN Leave
FOR I=1 TO GroupCount(Vgroup)
        V1= GroupElement(Vgroup,I)
        Var_type=NamedVarCategory(V1)
        IF Var_type= WsVariationVars THEN
                IF NOT IsEntReferenced(V1) THEN
			Vname$= EntityNameStr(V1)
			IF POS(Vname$,Prefix$)= 1 THEN
                        	Stat= DeleteEntity(V1)
				Stat= OutputString(File$,Vname$&Lf$,WsAppend)
			END IF
                END IF
        END IF
NEXT I
Stat=DeleteEntity(Vgroup)
Stat= OutputString(File$,Lf$,WsAppend)
Stat= MessageFileBox(File$,"Variables deleted")

GOTO Start

Leave:!
Stat=SetInputFormat("n4","")

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

