
! script name: vitems.d/itemfromprop
! var_topic: make an item from an existing info packet

!A
!A NAME:
!A
!A 	Item from Packet
!A
!A DESCRIPTION:
!A
!A 	This script makes an item flag from a existing info packet.  This
!A 	allows you to make info flags from packets obtained by querying the
!A 	database.
!A
!B INSTRUCTIONS:
!B
!B 	EXISTING ITEM FLAGS: Select an existing info packet.
!B
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm
!# see also - htdocs/help.d/query.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: make item from property")

DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Prop_name$[256]
DIM Item_name$[256]
DIM Prop_class$[256]
DIM Class_name$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave


DeActivateUndo
Start:!
Existing_props:!
Group1= GrpOfUserProps
IF NOT GroupCount(Group1) THEN Leave
Group= CreateGroup("")
FOR I=1 TO GroupCount(Group1)
        E1= GroupElement(Group1,I)
        IF IsEntityDependent(E1)= WsTrue THEN
                Stat= AddToGroup(Group,E1)
        END IF
NEXT I
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_prop_record:!
Stat= GenerateVarName(WsDataStringEnt,Item_name$)
RecordFunctionOn
Stat=RecordDescr("ITEM:"&Class_name$)
Item_ent= CopyEntity(Prop_name$)
Stat= ChUserPropType(Item_ent,NextItemNumber)
Stat= NameEntity(Item_ent,Item_name$)
RecordFunctionOff
CloseVarRecord
IF NOT ValidGeometry(Item_ent) THEN
        DelLastVarRecord
        GOTO Start
END IF
GOTO Start

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

