Author Topic: Export elements from several subpackages to CSV  (Read 1891 times)

Eamonn John Casey

  • EA User
  • **
  • Posts: 110
  • Karma: +0/-1
    • View Profile
Export elements from several subpackages to CSV
« 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?

qwerty

  • EA Guru
  • *****
  • Posts: 10578
  • Karma: +232/-191
  • I'm no guru at all
    • View Profile
Re: Export elements from several subpackages to CSV
« Reply #1 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.

rupertkiwi

  • EA User
  • **
  • Posts: 94
  • Karma: +3/-0
    • View Profile
Re: Export elements from several subpackages to CSV
« Reply #2 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

peterc

  • EA User
  • **
  • Posts: 83
  • Karma: +4/-0
    • View Profile
Re: Export elements from several subpackages to CSV
« Reply #3 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.

Arshad

  • EA User
  • **
  • Posts: 188
  • Karma: +11/-1
    • View Profile
« Last Edit: February 19, 2018, 10:04:30 pm by Arshad »