
! script name: vnames.d/namecontour
! var_topic: assign a name to a contour

!A
!A NAME:
!A
!A 	Name Contour   --- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a name to be assigned to an contour.
!A
!B INSTRUCTIONS:
!B
!B 	CONTOUR NAME: Enter the name to be associated with the contour.
!B
!B 	NAME IN USE, Proceed: If a duplicate name is entered, this option
!B 		appears.  Proceed will return to the ENTITY NAME question.
!B
!B 	PICK ELEMENT TO BE NAMED: Pick the element to be named.
!B
!C NOTE:
!C
!C	This script has an optional parameter called Static_name.
!C	If this parameter is set to 1 then the variational record
!C	which makes the name will create the name in such a way
!C	that it will not change when making a strategy.
!C	This can be a useful feature when a developer wishes to
!C	use a strategy to give a contour a specific name.
!C	The developer must assume responsibility for
!C	name conflicts.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: name contour ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM A$[256]


IF ARGC>1 THEN
        A$= ARGV(1)
        Static_name= VAL(A$)
ELSE
        Static_name=0
END IF

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo
Ploop: !
Stat=SetInputFormat("a99","")
Stat=GetValue("CONTOUR NAME",Answer$)
IF ExitScript(Destination$) THEN Leave
Name$=Answer$

E1=FindNamedEntity(Name$)
IF ValidGeometry(E1) THEN
	Stat=SetInputFormat("a1",",P,")
	Stat=GetValue("NAME IN USE, Proceed",Answer$)
	IF ExitScript(Destination$) THEN Leave
	GOTO Ploop
END IF

Pick_entity: !
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR TO BE NAMED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_entity
Stat=EntityNameCheck(Contour,Contour$)

IF Static_name THEN
	RecordFunctionOn
	Stat=RecordDescr("NAME: Static name contour")
	V1= StringConstant(Name$)
	Stat=ChangeGrpName(Contour$,V1)
	RecordFunctionOff
	CloseVarRecord
ELSE
	RecordFunctionOn
	Stat=RecordDescr("NAME: Name contour")
	Stat=ChangeGrpName(Contour$,Name$)
	RecordFunctionOff
	CloseVarRecord
END IF

GOTO Ploop

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

