
! script name: vitems.d/unlinkentitems
! var_topic: unlink item references from an entity.

!A
!A NAME:
!A
!A 	Unlink Entity Items
!A
!A DESCRIPTION:
!A
!A 	This script unlinks item references from an entity or group.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP:  Single: Pick the group
!B 		or switch to single element pick.
!B
!B 	PICK ELEMENT:  Group: Pick the
!B 		element or switch to group pick.
!B

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

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo

Pick_entity: !
Stat=SetInputFormat("n4a1",",G,")
Element=PickEntity("PICK ELEMENT TO BE UNLINKED:  Group ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="G" THEN Pick_group
IF NOT ValidDependency(Element) THEN Pick_entity
Stat=EntityNameCheck(Element,Element$)
GOSUB Make_record
GOTO Pick_entity

Pick_group: !
Stat=SetInputFormat("n4a1",",S,N,")
Group=PickGroupEnt("PICK GROUP TO BE UNLINKED:  Single, Name ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="S" THEN Pick_entity
IF Answer$="N" THEN 
	GOSUB Get_named_grp
END IF
IF NOT ValidDependency(Group) THEN Pick_group
Stat=EntityNameCheck(Group,Element$)
GOSUB Make_record
GOTO Pick_group

Get_named_grp:!
Stat=ListGrpNames("GROUP NAMES","selected group","",0)
IF Stat=1 THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Group=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Group) THEN Get_named_grp
Stat=SetInputFormat("n4","")
LowerSelectBox
RETURN

Make_record:!
RecordFunctionOn
Stat=RecordDescr("PROPERTY: Unlink entity items")
Stat= UnAssocEntItems(Element$)
RecordFunctionOff
CloseVarRecord
RETURN

Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

