
! script name: vproperty.d/entpropref
! var_topic: entity info packet reference

!A
!A NAME:
!A
!A 	Copy Attached Packet
!A
!A DESCRIPTION:
!A
!A 	This script establishes a variational record that makes a
!A 	variational copy of an info packet attached to an existing entity.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity that references the info packet. If the 
!B 	entity has more than one info packet attached to it, Synergy will pop
!B 	up a selection box, letting you choose from the attached properties.
!B
!C NOTES:
!C
!C 	This script is designed for use in variational strategies.  It
!C 	allows a strategy to reference an info packet attached to an entity.
!C
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: entity property 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= EntUserPropGrp(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 INFO PACKETS","Packet selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT INFO PACKET 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("PACKET REFERENCE:"&Class_name$)
V1= StringConstant(Class_name$)
Prop_ent= CopyEntity(EntUserPropRef(Element$,V1))
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


