
! script name: layers.d/componentbox
! topic: set component numbers on a group of elements in box

!A
!A NAME:
!A
!A 	Component in Box
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of elements within a box to be assigned
!A	a component number.
!A
!B INSTRUCTIONS:
!B
!B 	COMPONENT NUMBER,   current component= # : Enter the component number 
!B 		to be assigned to the elements selected.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that the elements are in.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: component in box ")

DIM Destination$[256]
DIM Answer$[256]

CALL Convert_old_origins
Component=CurrentComponent

ActivateUndo
stat= SetInputFormat("n0=","")
stat= SetEqualsValue(Component)
Component=GetValue("COMPONENT NUMBER,   current component= "&VAL$(Layer))
IF (ExitScript(Destination$)) THEN Leave
stat= SetInputFormat("n4","")

Group_loop:!
Group=CreateGroup("TEMPGROUP")


Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("set work zone")
Stat= AddGroupToUndo(WsUBModifyMode,Group,0,WsFalse)

Stat=SetComponent(Group,Component)
Stat=DeleteEntity(Group)

GOTO Group_loop

Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Group)
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
