Displaying items by tag: xmi file import
Importing Visio Diagrams into Enterprise Architect
If you are not using Enterprise Architect to design your systems, you are giving up opportunities for increased productivity, that result from re-using your data across the whole project, sharing that data across the entire project team and using the model to drive the solution.
Enterprise Architect delivers the capacity for data sharing and re-use, achieving synergies and efficiencies that can only be realized using an integrated development environment.
You could be reaping the benefits of Enterprise Architect in less than twenty minutes!
For more information, please visit the following pages:
To learn how to move from Microsoft Visio to Enterprise Architect, please visit:
http://www.sparxsystems.com/products/visio-importer/moving-from-visio-to-enterprise-architect.html
Sparx Enterprise Architect script : XMI file batch import
A colleague recently enquired about a simple way to run a batch import of several XMI files into an Enterprise Architect project. The client's project required importing a rather large number of XMI files, created from various Enterprise Architect projects via the standard XMI export (note : each file store an extraction in the XMI format from a selected part of the modelling project). Having to import each XMI file is too cumbersome, and Enterprise Architect's existing "Batch XMI Import" is limited to controlled packages i.e. involving a VC repository like SVN set up with the current project.
This article explains how to create in your Enterprise Architect project a VBScript that can be used import a batch of XMI files, located on a local or networked drive, within a selected package from the browser.
Step 1: open the scripting view using the menu Tools > Scripting.
Step 2: click on "new normal group" to store all user-defined scripts, e.g. MyScripts.
Step 3: click on "new script > new VBScript" to define the Batch XMI Import script, e.g. BatchXMIImport.
Step 4: open the script and copy/paste the following content (or download the VBScript text file here).
- option explicit
- !INC Local Scripts.EAConstants-VBScript
- '
- ' Script Name: XMIImportFiles
- ' Author: G.Finance guillaume[at]umlchannel.com
- ' Purpose: Batch import of XMI files to the selected package
- ' Date: 13/01/2014
- ' HOW TO USE : 1. Set the target directory in the targetFolderA variable (use \\ for each backslash) ; you may enable additional folders if required
- ' 2. Add each XMI filename to process into the "fileList" array variable
- ' 3. Run the script
- '
- '
- ' [USER ACTION 1] : update the target folder where the files to process are located
- dim targetFolderA
- targetFolderA = "C:\\temp\\"
- ' Additional target folders to use if required
- 'dim targetFolderB
- 'targetFolderB = "D:\\"
- 'dim targetFolderC
- 'targetFolderC = "E:\\"
- '
- '
- ' ArrayList Object to store the name of each file to process (including the folder name, using one of the "targetFolder" variables)
- dim fileList
- Set fileList = CreateObject("System.Collections.ArrayList")
- ''[USER ACTION 2] : update the following list with the name of each file to process, specifying first the associated targetFolder variable
- fileList.Add targetFolderA + "class.xml"
- fileList.Add targetFolderA + "deploy.xml"
- fileList.Add targetFolderA + "uc.xml"
- ''add new lines above if required
- dim projectInterface as EA.Project
- dim result
- set projectInterface = Repository.GetProjectInterface()
- sub XMIImportFiles()
- Repository.EnsureOutputVisible "Script"
- Repository.ClearOutput "Script"
- Session.Output( "VBScript XMI Import Files" )
- Session.Output( "=======================================" )
- ' Get the selected package to import the XMI files
- dim contextObjectType
- contextObjectType = Repository.GetContextItemType()
- ' Check if the selected element is a package ; if not display a message and exit
- if contextObjectType = otPackage then
- ' Get the context object as a package
- dim contextPackage as EA.Package
- set contextPackage = GetContextObject()
- Session.Output( "Selected Package : " & contextPackage.Name )
- Session.Output("TARGET PACKAGE GUID = " & contextPackage.PackageGUID & "(ID : " & contextPackage.PackageID & ")" )
- ' Process each XMI file set in the fileList Array Object
- Dim xmiFile
- For Each xmiFile In fileList
- Session.Output("Processing " & xmiFile & "..." )
- ''Import the content of the XMI file to the selected package
- result = projectInterface.ImportPackageXMI(projectInterface.GUIDtoXML(contextPackage.PackageGUID), xmiFile, 1, 1)
- Session.Output(result)
- Next
- }
- else
- ' Package is not currently the context item
- MsgBox( "This script requires a package to be selected." & vbCrLf & _
- "Please select a package and try again." )
- end if
- end sub
- XMIImportFiles
Step 5: set the folder name(s) and filenames to process by updating the script's content.
- Let's say you need to import C:\old\usecases.xml and C:\current\class.xml XMI files, created from a separate EA project.
- Update targetFolderA variable on line 15, using \\ for each backslash: targetFolderA = "C:\\current\\"
- Uncomment targetFolderB variable on line 17: dim targetFolderB
- Update targetFolderB variable on line 18: targetFolderB = "C:\\old\\"
- Set the values in the ArrayList object (from line 27): fileList.Add targetFolderA + "class.xml", fileList.Add targetFolderB + "usecases.xml"
- Save (ctrl-S)
Step 6: select the target package (or view) from the Project Browser, and click on the "run script" to import all XMI Files (important : it is not possible to select a Model Root as the target)
Note: results and notification messages are displayed in the System Output view (opened automatically once the script starts running)
Result: the content of both XMI files is available from the selected package within the Project Browser.
Note : if your XMI file contains a model root, or a view (package at N+1 level) such as "test" from the above Project Browser illustration, it will be imported as a package within the selected package or view.