
! script name: vtools.d/mergepropgrps
! var_topic: merge two groups of tools

!A
!A NAME:
!A
!A 	Merge Tool Groups	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script combines two groups. This script must be used with care
!A	in variational design. 
!A
!B INSTRUCTIONS:
!B
!B 	FIRST FIRST GROUP: Pick the first group of tools to be combined.
!B			  The second groups elements will be appended
!B			  to this group.
!B
!B 	SECOND NEXT GROUP: Pick the other group of tools to be combined.
!B			 This group will no longer exist.
!B
!C NOTE:
!C
!C	If it is known that the tools are not attached to entities
!C	then the reassociate variable can be set equal to 0. This
!C	may save some execution time for this function.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: merge tools 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("TOOL GROUPS","selected group","",WsGrpOfTools)
IF Stat=1 THEN Leave
Stat=SetInputFormat("a99","")
Stat=GetValue("FIRST TOOL GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Tool_group1=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Tool_group1) THEN Start
Stat= EntityNameCheck(Tool_group1,Group1$)
Stat=SetInputFormat("n4","")

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


Make_record:!
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TOOL GROUP: Combine Tool Groups")
G1=GroupUnion(Group1$,Group2$)
stat= DeleteEntity(Group1$)
stat= DeleteEntity(Group2$)
V1= FreeParameter("Reassociate",1)
Stat= RmDupToolsInGrp(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
