
! script name: vproperty.d/entpropupdate
! var_topic: update an entity's info packets with data from another entity

!A
!A NAME:
!A
!A 	Update Attached Packet
!A
!A DESCRIPTION:
!A
!A 	This script establishes a variational record which updates
!A 	the data in an info packet with data from another info packet.
!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 allows
!C 	a strategy to reference an info packet attached to another entity.
!C
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: update entity property data")

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 Source_prop$[256]
DIM Class_dir$[256]
DIM Class_name$[256]
DIM Source_class$[256]
DIM Filename$[256]
DIM D_label$[256]
DIM Choice$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave


Start:!
DeActivateUndo
Stat=SetInputFormat("n4","")

Existing_props:!
Group1= GrpOfUserProps
Group= DependentSubGroup(Group1)
Stat= DeleteEntity(Group1)
IF NOT GroupCount(Group) THEN New_prop
Stat=UserSelectBox("EXISTING INFO PACKETS","Packet selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("SOURCE PACKET ID NAME",Name$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Name$
CASE "CANCEL"
        Stat= DeleteEntity(Group)
        GOTO New_prop
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,Source_prop$)
Source_class$= UserDataStr(Prop_ent,"Class name:")
Stat= DeleteEntity(Group)
LowerSelectBox
GOTO Pick_entity


Pick_entity:!
Stat= SetInputFormat("n4a1",",G,")
E1=PickEntity("DESTINATION 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$)

Prop_ent= EntUserPropRef(E1,Source_class$)
IF NOT ValidGeometry(Prop_ent) THEN 
	Stat=SetInputFormat("a99","")
	Stat=GetValue("NO SIMILAR PACKET ATTACHED   Proceed",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	GOTO Start
END IF
Found_prop:!
Stat= EntityNameCheck(Prop_ent,Prop_name$)
Class_name$= UserDataStr(Prop_ent,"Class name:")
LowerSelectBox
GOTO Make_prop_record


Make_prop_record:!
RecordFunctionOn
Stat=RecordDescr("INFO PACKET DATA UPDATE:"&Class_name$)
V1= StringConstant(Class_name$)
V2= StringConstant(UserData(Source_prop$))
Stat= ReplaceUserData(EntUserPropRef(Element$,V1),V2)
RecordFunctionOff
CloseVarRecord




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


