Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated method to export Enterprise Architect diagrams?

Problem: A lot of our design and architecture documentation were created and maintained in Enterprise Architect - for better or worse, that is how it is. These documents are stored in our subversion repository - which works out pretty well for the folks that create and update them - since we have licenses for EA - but many of the developers (both internal and external) who work on our codebase and need to make use of the diagrams but dont all have EA licenses.

Poor Solution: We could manually export the EA documents to a portable format and then check those in, but there are bound to be times when the portable format version is out of date with the EA document since it relies on the human to take the steps to manually convert.

Better Solution: We have been looking for a method to automate the conversion. This could be run as a post-commit hook or as part of our continuous integration system. The part we are missing is the piece that allows us to automate the conversion. Any ideas?

like image 279
Shane C. Mason Avatar asked Sep 17 '09 21:09

Shane C. Mason


Video Answer


2 Answers

In the Example code I just discovered a function whish will do exactly what you want. But hidden away by the not so helpfull name of ProjectInterfaceExample:

option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Examples of how to access and use the Project Interface.
' 
' Related APIs
' =================================================================================
' Project Interface API - http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.html
'

' Global reference to the project interface
dim projectInterface as EA.Project

sub ProjectInterfaceExample()

    ' Show the script output window
    Repository.EnsureOutputVisible "Script"

    Session.Output( "VBScript PROJECT INTERFACE EXAMPLE" )
    Session.Output( "=======================================" )


    set projectInterface = Repository.GetProjectInterface()

    ' Iterate through all model nodes
    dim currentModel as EA.Package
    for each currentModel in Repository.Models

        ' Iterate through all child packages and save out their diagrams
        dim childPackage as EA.Package
        for each childPackage in currentModel.Packages
            DumpDiagrams childPackage
        next
    next

    Session.Output( "Done!" )

end sub

'
' Recursively saves all diagrams under the provided package and its children
'
sub DumpDiagrams ( thePackage )

    ' Cast thePackage to EA.Package so we get intellisense
    dim currentPackage as EA.Package
    set currentPackage = thePackage

    ' Iterate through all diagrams in the current package
    dim currentDiagram as EA.Diagram
    for each currentDiagram in currentPackage.Diagrams

        ' Open the diagram
        Repository.OpenDiagram( currentDiagram.DiagramID )

        ' Save and close the diagram
        Session.Output( "Saving " & currentDiagram.Name )
        projectInterface.SaveDiagramImageToFile "c:\\temp\\" + currentDiagram.Name + ".emf"
        Repository.CloseDiagram( currentDiagram.DiagramID )
    next

    ' Process child packages
    dim childPackage as EA.Package
    for each childPackage in currentPackage.Packages    
        DumpDiagrams childPackage
    next

end sub

ProjectInterfaceExample

You might have to fine tune it a litte (i.E. not writing everything into C:\Temp) but it is a good start.

like image 134
Martin Avatar answered Sep 24 '22 00:09

Martin


I am not familiar with this product but the Web site you link to mentions an Automation interface. This should allow you to control Enterprise Architect from a scripting language such as VBScript or JavaScript. It may be possible to print via this interface; if so, you could install a PDF printer driver (or print to a file using a generic PostScript printer driver and use GhostScript to convert it to PDF.

like image 40
Ken Keenan Avatar answered Sep 25 '22 00:09

Ken Keenan