APSF,0,,-1,-1;-1;-1;-1;-1;+00;-00;-0;-;-;-;-;;-|;-|;-|;+;+ // Merge Plans - merges the objects from one open plan into another function CompareFields(mtype as integer, a as string, b as string) as boolean if mtype=0 then return a=b else return instr(a,b)>0 or instr(b,a)>0 end if end function dim pnames(-1),cabbrev(-1) as string dim i,source,target,match,dups,mark,isrc,itarget,mtype,nconst as integer dim sourceObjects(-1),src as APPlanObjectData dim newobj,tgt as APPlanObject dim found as boolean // Get parameters using a dialog if nPlans<2 then print "At least 2 plan documents must be open" return end if for i=1 to nPlans pnames.Append GetPlanName(i) next target=CurrentPlanNumber-1 if target=0 then source=1 else source=0 //SetCaptionParameter("Merge objects from the source plan into the target plan",1,true,false,false,false,true) SetPopupParameter("Source plan",source,pnames) SetPopupParameter("Target plan",target,pnames) SetChoiceParameter("Match on",2,"ID only","Name only","ID and/or Name") SetChoiceParameter("Match type",1,"Equality (A = B)","Inclusion (A in B or B in A)") SetChoiceParameter("Duplicates",0,"Discard/Ignore","Make duplicate object","Replace existing entry") SetChoiceParameter("Mark merged objects",0,"No","Prefix Notes field with [New] or [Replaced]") cabbrev=ConstellationAbbreviations cabbrev.Insert 0,"All" SetPopupParameter("Restrict to constellation",0,cabbrev) if not EditParameters("Merge Plan Objects") then return source=GetPopupParameter("Source plan")+1 target=GetPopupParameter("Target plan")+1 if source=target then print "Source and target must be different plans" return end if match=GetChoiceParameter("Match on") dups=GetChoiceParameter("Duplicates") mark=GetChoiceParameter("Mark merged objects") mtype=GetChoiceParameter("Match type") nconst=GetPopupParameter("Restrict to constellation") // Get the source objects SelectPlan(source) for i=1 to nObjects if nconst=0 or Obj(i).Constellation=cabbrev(nconst) then sourceObjects.Append Obj(i).Contents end if next SelectPlan(target) // Merge the new objects into the target StartProgress("Merging objects", true, ubound(sourceObjects)) for isrc=0 to ubound(sourceObjects) if UpdateProgress(isrc) then exit src=sourceObjects(isrc) newobj=nil if dups=1 then // Always create a new entry newobj=NewObject else // Check for duplicates found=false for itarget=1 to nObjects tgt=Obj(itarget) select case match case 0 // ID only if src.ID<>"" and CompareFields(mtype,src.ID,tgt.ID) then found=true case 1 // Name only if src.Name<>"" and CompareFields(mtype,src.Name,tgt.Name) then found=true case 2 // ID or Name if src.ID<>"" and CompareFields(mtype,src.ID,tgt.Name) or _ src.Name<>"" and CompareFields(mtype,src.Name,tgt.ID) then found=true end select if found then exit next if found then if dups=2 then tgt.Contents=src if mark=1 then tgt.Notes="[Replaced] "+tgt.Notes end if else newobj=NewObject end if end if if newobj<>nil then newobj.Contents=src if mark=1 then newobj.Notes="[New] "+newobj.Notes end if next StopProgress