
! script name: items.d/unassocitems
! topic: remove item flag references from an entity

!A
!A NAME:
!A
!A 	Remove Item Flag references from an entity
!A
!A DESCRIPTION:
!A
!A 	This script will remove item flag references from an entity.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT ENTITY, Unselect, Remove references:  Pick the element to be
!B 	modified.
!B
!B 		U - Unselect works in a recursive manner.  The elements will be
!B 		    unselected in the reverse order in which they were selected.
!B 		R - Remove references will finialize the removal 
!B 		    of the item referenced.
!B
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: remove item references ")

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


DeActivateUndo
Start: !
Group=CreateGroup("TEMPGROUP")

Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Ploop:!
Answer$=""
Choice$=""
IF NOT GroupCount(Group) THEN

  E1=PickEntity("SELECT ENTITY")

ELSE

  Stat=SetInputFormat("a1",",U,R,")
  E1=PickEntity("SELECT ENTITY, Unselect, Remove references ",Answer$)

END IF

IF (ExitScript(Destination$)) THEN Leave
Choice$=UPC$(Answer$)

SELECT Choice$

   CASE "U"

      Element_num=GroupCount(Group)
      Temp_e1=GroupElement(Group,Element_num)
      IF NOT ValidGeometry(Temp_e1) THEN Ploop
      Stat= SetSelectedFlag(Temp_e1,WsFalse)
      Stat=PlotEntity(Temp_e1)
      Stat=RemoveFromGrp(Group,Element_num)

   CASE "R"

	Stat= UnAssocEntItems(Group)
        Stat= SetSelectedFlag(Group,WsFalse)
        Stat=PlotEntity(Group)
      	Stat=DeleteEntity(Group)
      	GOTO Start

   CASE ELSE

      IF NOT ValidGeometry(E1) THEN Ploop
      Stat= SetSelectedFlag(E1,WsTrue)
      Stat=AppendToGroup(Group,E1)
      Stat=PlotEntity(E1)

END SELECT

GOTO Ploop

Leave:!
IF ValidGeometry(Group) THEN
        Stat= SetSelectedFlag(Group,WsFalse)
        stat= PlotEntity(Group)
        stat= DeleteEntity(Group)
END IF

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