
! script name: vproperty.d/mergepropgrps
! var_topic: merge two groups of info packets

!A
!A NAME:
!A
!A 	Merge Packet Group
!A
!A DESCRIPTION:
!A
!A 	This script combines two info packet groups. Be careful when using this 
!A 	script in combination with variational design. 
!A
!B INSTRUCTIONS:
!B
!B 	FIRST GROUP: Pick the first group of info packets you want to combine.
!B 	The second group of elements will be appended to this group.
!B
!B 	SECOND GROUP: Pick the group of information packets you want combined 
!B 	with the group you just selected.  This group will no longer exist, so
!B 	before running this script you might want to make a back up of the
!B 	second group.
!B
!C NOTES:
!C
!C 	You may be able to save some execution time for this function.
!C 	If you know that the info packets are not attached to entities
!C 	the "Reassociate" variable can be set to zero. 
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: merge property groups ")

DIM Answer$[256]
DIM Destination$[256]
DIM Group1$[256]
DIM Group2$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave


DeActivateUndo
Combine_loop:!
Stat=ListGrpNames("PACKET GROUPS","selected group","",WsGrpOfProperties)
IF Stat=1 THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("FIRST PACKET GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Prop_group1=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Prop_group1) THEN Start
Stat= EntityNameCheck(Prop_group1,Group1$)
Stat=SetInputFormat("n4","")

Stat=ListGrpNames("PACKET GROUPS","selected group","",WsGrpOfProperties)
IF Stat=1 THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("SECOND PACKET GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Prop_group2=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Prop_group2) THEN Start
Stat= EntityNameCheck(Prop_group2,Group2$)
Stat=SetInputFormat("n4","")


Make_record:!
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PACKET GROUP: Combine Packet Groups")
G1=GroupUnion(Group1$,Group2$)
stat= DeleteEntity(Group1$)
stat= DeleteEntity(Group2$)
V1= FreeParameter("Reassociate",1)
Stat= RmDupPropsInGrp(G1,V1)
Stat= NameEntity(G1,Name$)
RecordFunctionOff
CloseVarRecord

GOTO Combine_loop

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

