
! script name: workzones.d/namezones
! topic: name a component

!A
!A NAME:
!A
!A 	Name Work Zone
!A
!A DESCRIPTION:
!A
!A 	This script will name a component.
!A
!B INSTRUCTIONS:
!B
!B 	NO HELP AVAILABLE AT THIS TIME
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: name work zone")

DIM Answer$[256]
DIM Destination$[256]
DIM Dir$[256]
DEG

CALL Convert_old_origins
WsNamedComponent= 7041776
Sep$= CHR$(9)
Dir$= "/usr/weber/userdata/"

Group_loop:!
Stat=SetInputFormat("n4","")
Component=InputComponent("INPUT WORK ZONE NUMBER")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("WORK ZONE NAME",Answer$)
IF ExitScript(Destination$) THEN Leave

Ncomp=ReadUserData(WsNamedComponent,Answer$,FileNameString(Dir$,"workzones"))
IF ValidGeometry(Ncomp) THEN Stat=PutUserValue(Ncomp,"Component:",Component)

GOTO Group_loop

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

SUB Convert_old_origins
DIM Answer$[256]
DIM Zone_name$[256]

G1= UserDataGroup(WsWorkZoneOrigin)
IF NOT ValidGeometry(G1) THEN SUBEXIT
Num_origins= GroupCount(G1)

FOR I= 1 TO Num_origins
        E1= GroupElement(G1,I)
        IF CheckUserField(E1,"Class id number:",1) THEN Next_i
        Group1= GrpByProp(E1,WsWorkZoneOrigin)
        IF NOT ValidGeometry(Group1) THEN Next_i
        IF NOT GroupCount(Group1) THEN Next_i
	GOTO End_it
Next_i: NEXT I
Stat=DeleteEntity(G1)
SUBEXIT
End_it:	Answer$="/usr/weber/database/messages/convert_old_zones"
	Stat=MessageFileBox(Answer$,"INFORMATION")
	Stat=DeleteEntity(G1)
	Stat=DeleteEntity(Group1)
SUBEND
