
! script name: items.d/unlinkitem
! topic: unlink an item flag

!A
!A NAME:
!A
!A 	Unlink an Item Flag
!A
!A DESCRIPTION:
!A
!A 	This script unlinks the entities within an item flag.
!A 	It also deletes the item flag entity.
!A
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: unlink items ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM A$[256]
DIM B$[256]
DIM List$[32000]


DeActivateUndo
Start:!
Delete_group= CreateGroup("")
Group= GrpOfUserItems
IF NOT GroupCount(Group) THEN Leave

Pick_prop:!
List$=""
FOR I=1 TO GroupCount(Group)
	E1= GroupElement(Group,I)
	A$= UserDataStr(E1,"Class name:")
	B$= UserDataStr(E1,"Name:")
	N1= ElementGrpNum(Delete_group,E1)
	IF N1 THEN
		List$= List$&VAL$(I)&") deleted   "&A$&":  "&B$&","
	ELSE
		List$= List$&VAL$(I)&")  "&A$&":  "&B$&","
	END IF
NEXT I
Stat=GeneralListBox("ITEMS","Item selected",List$)

Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT ITEM, Undo, Cancel, Delete ",Name$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Name$
CASE "CANCEL"
	GOTO Leave
CASE "Delete", "D", "d", "delete"
	GOSUB Delete_props
	GOTO Start
CASE "Cancel", "C", "c", "cancel"
	Stat= DeleteEntity(Delete_group)
	Stat= DeleteEntity(Group)
	GOTO Start
CASE "Undo","U","u","undo"
	N1= GroupCount(Delete_group)
	Stat=RemoveFromGrp(Delete_group,N1)
	GOTO Pick_prop
END SELECT

Num1= NumericPrefix(Name$)
IF NOT Num1 THEN Pick_prop
Prop_ent= GroupElement(Group,Num1)
IF NOT ValidGeometry(Prop_ent) THEN Pick_prop

N1= ElementGrpNum(Delete_group,Prop_ent)
IF NOT N1 THEN
	Stat= AddToGroup(Delete_group,Prop_ent)
END IF
GOTO Pick_prop


Delete_props:!
FOR I= 1 TO GroupCount(Delete_group) 
	Prop_ent= GroupElement(Delete_group,I)
	Id_number=UserDataType(Prop_ent)
	Stat= UnAssocUserData(Prop_ent,Id_number)
	Stat= DeleteEntity(Prop_ent)
NEXT I
Stat= DeleteEntity(Delete_group)
Stat= DeleteEntity(Group)
RETURN

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