
! script name: vproperty.d/entitemref
! var_topic: entity item flag reference

!A
!A NAME:
!A
!A 	Copy Attached Item
!A
!A DESCRIPTION:
!A
!A 	This script establishes a variational record which makes a copy of an
!A 	item flag attached to an existing entity.  The record will create an
!A 	info packet that contains the data from the item flag.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity that references the item flag.  If the
!B 	entity has more than one info packet attached to it, Synergy will pop
!B 	up a selection box of all the entity's attached info packets.
!B
!C NOTES:
!C
!C 	This script is designed to be used in variational strategies.  It
!C 	allows a strategy to reference an item flag attached to an entity.
!C
!# see also - htdocs/help.d/property.htm

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

DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Element$[256]
DIM Prop_dir$[256]
DIM Prop_class$[256]
DIM Prop_name$[256]
DIM Class_dir$[256]
DIM Class_name$[256]
DIM Filename$[256]
DIM D_label$[256]
DIM Choice$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave


Start:!
DeActivateUndo
Pick_entity:!
Stat= SetInputFormat("n4a1",",G,")
E1=PickEntity("PICK ENTITY   Group ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "G" THEN
Pick_group:!
	E1=PickGroupEnt("PICK GROUP ")
	IF ExitScript(Destination$) THEN Leave
	IF NOT ValidDependency(E1) THEN Pick_group
END IF
Stat= EntityNameCheck(E1,Element$)

Group= EntityItemGroup(E1)
IF NOT ValidGeometry(Group) THEN Leave
Nprops= GroupCount(Group)
IF Nprops= 0 THEN Leave
IF Nprops=1 THEN
        Prop_ent= GroupElement(Group,1)
        Id_number= UserDataType(Prop_ent)
        Stat= DeleteEntity(Group)
        IF NOT ValidDependency(Prop_ent) THEN Start
	Class_name$= UserDataStr(Prop_ent,"Class name:")
ELSE
Existing_props:!
Stat=UserSelectBox("EXISTING ITEMS","Item selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT ITEM 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)
Class_name$= UserDataStr(Prop_ent,"Class name:")
LowerSelectBox
END IF


Make_prop_record:!
Stat= GenerateVarName(WsDataStringEnt,Prop_name$)
RecordFunctionOn
Stat=RecordDescr("ITEM REFERENCE:"&Class_name$)
V1= StringConstant(Class_name$)
Prop_ent= CopyEntity(EntItemPropRef(Element$,V1))
V2= FreeParameter("Class id number",GetUserValue(Prop_ent,"Class id number:"))
Stat= ChUserPropType(Prop_ent,V2)
Stat= NameEntity(Prop_ent,Prop_name$)
RecordFunctionOff
CloseVarRecord
IF NOT ValidGeometry(Prop_ent) THEN
        DelLastVarRecord
	GOTO Start
END IF




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


