
! script name: layers.d/setcomponent
! topic: assign single element to component

!A
!A NAME:
!A
!A 	Assign Component
!A
!A DESCRIPTION:
!A
!A 	This script allows a single element to be assigned to a component.
!A
!B INSTRUCTIONS:
!B
!B 	COMPONENT NUMBER,   current component= # : Enter the component number to
!B 		be assigned to the element selected.
!B
!B 	PICK ELEMENT TO BE ASSIGNED COMPONENT # : Pick the element to be
!B 		assigned to the component.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: assign component ")

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

ActivateUndo
CALL Convert_old_origins
Component=CurrentComponent

Stat=SetInputFormat("n0=","")
Component=InputComponent("COMPONENT NUMBER,   current component= "&VAL$(component))
IF (ExitScript(Destination$)) THEN Leave

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

E1=PickEntity("PICK ELEMENT TO BE ASSIGNED COMPONENT   "&VAL$(component))
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("set work zone")
Stat= AddItemToUndo(WsUBModifyMode,E1)

Stat=SetComponent(E1,component)

GOTO Ploop

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
