
! script name: items.d/BOMToggle
! topic: turn Bill of materials on or off on all entities in an item.

!A
!A NAME:
!A
!A 	Turn Bill of Materials On or Off
!A
!A DESCRIPTION:
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity. 
!B
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: BOM Toggle ")

DIM Destination$[512]
DIM Answer$[512]
DIM Name$[512]


ActivateUndo
IF ARGC > 1 THEN
	Answer$= ARGV(1)
	bom_on= VAL(Answer$)
ELSE
	bom_on= 0
END IF

Start:!

Parent_color= 3

Pick_entity:!
Stat= SetInputFormat("n4","")
E1=PickEntity("PICK ENTITY")
IF ExitScript(Destination$) THEN Leave


Item_group= EntityItemGroup(E1)
IF NOT ValidGeometry(Item_group) THEN Pick_entity
Nitems= GroupCount(Item_group)
IF Nitems= 0 THEN Leave
IF Nitems=1 THEN
        Item_ent= GroupElement(Item_group,1)
        Id_number= UserDataType(Item_ent)
        Stat= DeleteEntity(Item_group)
ELSE
Existing_items:!
Stat=UserSelectBox("EXISTING ITEMS","Item selected",0,WsPropGroupSelect,Item_group)

Pick_item:!
        Stat=SetInputFormat("a99","")
        Stat=GetValue("INPUT ITEM ID NAME",Name$)
        IF (ExitScript(Destination$)) THEN Leave
        SELECT Name$
        CASE "CANCEL"
        	Stat= DeleteEntity(Item_group)
                GOTO Start
        END SELECT
        Num1= NumericPrefix(Name$)
        IF NOT Num1 THEN Pick_item
        Item_ent= GroupElement(Item_group,Num1)
        IF NOT ValidGeometry(Item_ent) THEN Pick_item
        Stat= DeleteEntity(Item_group)
        LowerSelectBox
        Id_number= UserDataType(Item_ent)
END IF

IF ValidGeometry(Item_ent) THEN
	Stat= PlotEntity(Item_ent,Parent_color)

	ActivateUndo
	Stat= AdvanceUndoNumber("BOM On/Off")
	Stat= AddItemToUndo(WsUBModifyMode,Item_ent)

	Stat= SetBOMOnOff(Item_ent,bom_on)
END IF
GOTO Pick_entity





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