Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: Eamonn John Casey on February 18, 2018, 10:17:00 pm

Title: Export elements from several subpackages to CSV
Post by: Eamonn John Casey on February 18, 2018, 10:17:00 pm
I have a package With subpackages containing elements. Is there a way to Select the parent package and export all elements in the subpackages to a CSV file? Some wort of SQL maybe?
Title: Re: Export elements from several subpackages to CSV
Post by: qwerty on February 19, 2018, 02:44:32 am
You can copy the SQL results and they will be in CSV-format (almost, since if you have semi-colons in the result they will not be escaped). Use the #Branch# tag for a recursive package search.

q.
Title: Re: Export elements from several subpackages to CSV
Post by: rupertkiwi on February 19, 2018, 02:27:48 pm
Hi Eamonn,

EA ships with a script that will do this. I have adapted it slightly for my purposes and attached it below:


'option explicit

!INC Local Scripts.EAConstants-VBScript

sub RecursiveModelDumpExample()

Repository.EnsureOutputVisible "Script"
Repository.ClearOutput "Script"
Session.Output( "PackageContents" )
Session.Output( "=======================================" )
Dim thePackage As EA.Package
Set thePackage = repository.GetTreeSelectedPackage()
If Not thePackage Is Nothing And thePackage.ParentID <> 0 Then
      DumpPackage "", thePackage
      Else
   ' No package selected in the tree
   MsgBox ("This script requires a package to be selected in the Project Browser." & vbCrLf & _
      "Please select a package in the Project Browser and try again.")
End If
Session.Output ("Done!")
      
end sub

' Outputs the packages name and elements, and then recursively processes any child packages
' Parameters:
' - indent A string representing the current level of indentation
' - thePackage The package object to be processed
Sub DumpPackage(indent, thePackage)
    ' Cast thePackage to EA.Package so we get intellisense
    Dim currentPackage As EA.Package
    Set currentPackage = thePackage
    ' Add the current package's name to the list
    Session.Output (indent & currentPackage.Name & " (PackageID=" & currentPackage.PackageID & ")")
    ' Dump the elements this package contains
    DumpElementsNew indent & "    ", currentPackage
    ' Recursively process any child packages
    Dim childPackage As EA.Package
    For Each childPackage In currentPackage.Packages
        DumpPackage indent & "    ", childPackage
    Next 
End Sub

Sub DumpElementsNew(indent, thePackage)   
    ' Cast thePackage to EA.Package so we get intellisense
    Dim currentPackage As EA.Package
    Set currentPackage = thePackage   
    ' Iterate through all elements and add them to the list
    Dim currentElement As EA.Element
    For Each currentElement In currentPackage.elements
        Session.Output (indent & "::" & currentElement.Name & " (" & currentElement.Type & ", ID=" & currentElement.elementid & ")")
    Next   
End Sub

RecursiveModelDumpExample
Title: Re: Export elements from several subpackages to CSV
Post by: peterc on February 19, 2018, 07:04:23 pm
If you right-click on the parent package and select Import/Export - CSV Import/Export, then there is a tick-box for "Include Subfolders", which is ticked by default (at least on mine). If you build a specification with the appropriate items then it will export sub-packages as well.
Title: Re: Export elements from several subpackages to CSV
Post by: Arshad on February 19, 2018, 10:00:42 pm
Hi

Please have a look on MDG Integration for Microsoft office (https://sparxsystems.com.au/products/mdg/int/office/office-integration.html)
and  video on this by Sparx Systems  (https://www.youtube.com/watch?v=DkkxQ6SEB-w)