- You need a basic understanding of working with UML diagrams in Microsoft Visio 2010, as well as UML diagrams in IBM® Rational® Software Architect, Version 8.5.
- You need to understand the purpose of Sketcher diagram elements in IBM Rational Software Architect.
- It would be helpful to be aware of steps to generate .xmi files from UML diagrams in Visio. This article describes how to do that in Visio 2010, but the steps might be quite different for other versions of Visio.
Steps for importing a UML diagram
There are two pages in the Visio file that was used during import. The diagrams in Figures 1 and 2 show screen captures of both pages, which are titled Class-Diagram and UseCase-Diagram.
Figure 1. Class diagram drawn in Visio
Figure 2. Use case diagram drawn in Visio
1. Generate the .xmi file
Visio exposes only the visual information in a UML diagram, not the semantic information. However, it can generate a semantic file from a UML diagram. This file is generated in .xmi format and corresponds to XMI Version 1.0. You need this semantic file whenever the UML diagram contains at least one class diagram.
Follow these steps to generate the .xmi file in Visio 2010:
- Open the Visio UML diagram file.
- Press ALT + F11 (Alt and F11 keys simultaneously) to open a Microsoft Visual Basic window for the open UML diagram.
- Use the following function in the opened window and save it:
Sub ExportXMI() Application.Addons(UML Background Add-on).Run (/CMD=400 /XMIFILE=C:\work\ visiosamples\Sample.xmi) End Sub
- Select Run from the task bar at the top, and click Run Sub/UserForm from the drop-down menu.
Figure 3. Run the ExportXMI routine
- Directories mentioned in the path should exist in the local drive before you run this command.
- After running ExportXMI, a file named Sample.xmi will be created in this directory:
2. Create a target project
Bring up the New Project wizard in the Rational Software Architect workbench. A simple resource project is sufficient to store the imported diagrams.
Figure 4. New Project wizard
3. Import the Visio model into a project
There are multiple ways to launch the Visio Diagram Import wizard, but you can follow these steps for this example:
- Select the target project, and right-click, and then select Import on the context menu.
- In the Import wizard, from the Select page, click Modeling > Visio Diagram.
- Click Next.
Figure 5. Under Modeling, select Visio Diagram
4. Specify source and destination files
- Next to the "Source file" field, click the Browse button (see Figure 6), find and select the Visio file on your system, and then verify the selection by checking the preview image.
- For Diagram Type, select UML from the drop-down menu to indicate the target domain in Rational Software Architect as UML.
- As soon as you have selected UML, a field for the .xmi file is added. Click the Browse button next to .xmi file field to select the corresponding .xmi file.
- Under Destination, make sure that the appropriate project is selected.
Figure 6. Import Visio wizard dialog window
- After you provided all input, click Finish.
5. Monitor progress
As soon as you click Finish, the import process begins. The progress monitor reports the status of the import, as Figure 7 shows. You can cancel the import at any point.
Figure 7. Progress monitor
6. Review the import
When the import process finishes, it creates following resources, as the example in Figure 8 shows:
- A model resource (.emx), which contains UML diagrams and semantic information
- A profile resource (.epx), which contains the imported UML profile
- An HTML report that contains details about import
Figure 8. Imported model in the Project Explorer view
In the Diagrams folder in Project Explorer, double-click a diagram to view the imported diagram. The visual layout is similar to Visio.
Figure 9. Imported class diagram
If you are not able to import an element for some reason, that element will show as a Sketcher element in light red color in the same location. Details about why that element was not imported will be in the HTML report.
7. Review the report
After each Visio import, an HTML report is created in the Reports folder within the target folder that you selected in the import wizard. The report file name follows this convention:
<Visio source file name> <long format date and time>.html.
For example: Sample 2013-01-15 13-00-23.html
Figure 10. Import process report
Open the HTML report in a browser to view the details. The multiple sections begin with a summary that states the total time required for the import and the number of errors, information, and warnings reported by the import process.
Each table in the report consists of six columns:
- Serial number of a message within a table
- Severity of message: INFO, WARNING, or ERROR
- A short sentence that describes what happened (not why) during the import
- Type of Visio element that this message corresponds to: document, page, or shape type
- What action was taken by the import process (for example, if an element could not be imported and a Sketcher element is drawn, then drawing a Sketcher element is the action taken)
- Hyperlinked text that describes details about the message type
8. Find elements that could not be imported
There are two ways to locate an element that you were not able to import:
- You can open the diagram and look for light red Sketcher element. But this is cumbersome when there are dozens of diagrams and many shapes in each diagram, and opening each page and looking for Sketcher elements is time-consuming.
- The better option is to create a task for each element that was not imported. You can open the Tasks view, double-click a task, and that will take you to that corresponding Sketcher element in a diagram.
9. Use the imported model for transformation
You can use the imported model for many UML-related transformations in Rational Software Architect. There is one point to keep in mind for that: The top-level element type of the imported model is Model type, but transformations in Rational Software Architect expect top-level element types to be Package. However, you can convert Model to Package by right-clicking Model and selecting Refactor > Convert Model to Package. Then the top-level element type is Package and it is ready to use in transformations.
Important points to remember
- Not all class diagram elements are generated in .xmi. No attempt is made to import elements that are not present in the .xmi file. Therefore, the usual approach is to show the Sketcher shape for elements that cannot be imported.
- Sometimes, a user makes a mistake in connecting two elements in Visio. Visually they could look like they are connected, but if it is inspected carefully (by zooming) it is noticed that they are actually not connected. Visio does not generate semantic information (in .xmi) for such connections. Most of the disconnected connections are imported but not all. For example, disconnected Association connection is not imported. Details of why a connection could not be made are in the report.
- The .vdx and .xmi files are independent, so mapping should be done to map a shape in the .vdx file to an element in the .xmi file. Name and type of shape distinguish between elements. For some shape types, for example the Class, even attribute and operation compartments are parsed to differentiate between two shapes (if their names are the same). Occasionally, two elements of the same type and same name cannot be imported. This means that no mapping from a shape in .vdx to an element in .xmi could be found. (Explaining why is beyond the scope of this article.)
There is only one preference for a UML import.
- In the Preferences page, type
umlin the text field.
- Select the page named UML: Modeling > Visio Import > UML, where you will find a box checked for "System attempts to resolve potential ambiguity."
Figure 11. UML import preference
This preference maps the semantic model to the visual model. It is related to mapping between a shape in the Visio file and the corresponding element in the .xmi file that contains semantic information. These two files (.vdx and .xmi) are independent, and you need a mechanism to match shapes in .vdx and elements in .xmi. Selecting this preference will match two shapes with identical names, attributes, and so forth. For example, if there are two shapes that are of the UML class type, both are named Person, and both have identical attributes and operations, it is impossible to distinguish between them in .xmi.
Checking the preference check box will match the shape and corresponding element randomly. This is done only for shapes that don't have connection shapes connected to them. This is safe, because the two classes are identical anyway.
There are several benefits of importing Visio UML diagrams into Rational Software Architect:
- Rational Software Architect supports UML 2.2, so, essentially, a model is transformed into UML 2.2.
- UML profiles are supported extensively in Rational Software Architect. This helps in the extension of a model.
- Extensive features of Rational Software Architect, such as model-to-model transformation, can be used on the imported model.
- To learn more:
- Start at the Rational Software Architect family of products page and be sure to check the developerWorks page.
- Explore What's new in Rational Software Architect 8.5 and see the Rational Software Architect 8.5 Information Center for detailed installation and use instructions.
- For additional resources, check Rational Software Architect 8.5 page and the Rational Software Architect wiki.
- Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Improve your skills. Check the Rational training and certification catalog, which includes many types of courses on a wide range of topics. You can take some of them anywhere, anytime, and many of the Getting Started ones are free.
Get products and technologies
- Download any of these for a trial at no charge:
- Evaluate IBM software in the way that suits you best: Download it for a trial, try it online, use it in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement service-oriented architecture efficiently.
- Join the discussion in the Rational Development Tools forum on developerWorks and the Using Design Management forum on Jazz.net.
- Get connected with your peers and keep up on the latest information in the Rational community.
- Rate or review Rational software. It's quick and easy.
- Share your knowledge and help others who use Rational software by writing a developerWorks article. Find out what makes a good developerWorks article and how to proceed.
- Follow Rational software on Facebook, Twitter (@ibmrational), and YouTube, and add your comments and requests.
- Ask and answer questions and increase your expertise when you get involved in the Rational forums, cafés, and wikis.