
! script name: vitems.d/unlinkitem
! var_topic: unlink an item flag

!A
!A NAME:
!A
!A      Unlink Item
!A
!A DESCRIPTION:
!A
!A      This script unlinks an item flag, removing it from VDM.
!A
!B
!B
!C NOTES:
!C
!C      Unlinking an item will remove only the item reference selected.
!C      Any other item flag references on the entities will be
!C      maintained. Once an item flag has been removed it can be
!C      re-established by using the "Attach Item" scripts.
!C
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: unlink item")

DIM Destination$[512]
DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM Name$[512]
DIM Element$[512]
DIM Prop_name$[512]
DIM Prop_class$[512]
DIM Class_name$[512]
DIM Data$[32000]
DIM D_label$[512]
DIM Sub_label$[512]
DIM F_label$[512]
DIM Choice$[512]
DIM Ques$[512]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave


DeActivateUndo
Start:!
Existing_props:!
Group1= GrpOfUserItems
Group= DependentSubGroup(Group1)
Stat= DeleteEntity(Group1)
IF NOT GroupCount(Group) THEN Leave
Stat=UserSelectBox("EXISTING ITEMS","Item selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT ID NAME",Name$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Name$
CASE "CANCEL"
	Stat= DeleteEntity(Group)
	GOTO Leave
END SELECT

Num1= NumericPrefix(Name$)
IF NOT Num1 THEN Pick_prop
Prop_ent= GroupElement(Group,Num1)
IF NOT ValidDependency(Prop_ent) THEN Start
Stat= EntityNameCheck(Prop_ent,Prop_name$)
Stat= DeleteEntity(Group)
LowerSelectBox

Make_record:!
RecordFunctionOn
Stat=RecordDescr("UNLINK ITEM:"&Prop_name$)
Stat= UnAssocUserData(Prop_name$,UserDataType(Prop_name$))
Stat= DeleteEntity(Prop_name$)
RecordFunctionOff
CloseVarRecord

GOTO Start

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

