This tip is the ninth in a series of tips that describe System Architect's VBA and show you how to build a simple macro that gets information from the repository. In this series, you create a macro, use System Architect's object model to access an encyclopedia, access diagrams in the encyclopedia, get symbols on a diagram, and get information from the definition of a symbol.
In the last tip, we got information on symbols, then opened a diagram and got diagrammatic information on a symbol. In this tip we'll open a specific diagram, get information about the definition of a symbol.
If you have closed the work you did in the last tip, reopen it by performing the following steps:
- In System Architect, with the Samples encyclopedia open, select Tools, Macros, VBA Editor to open the VBA IDE.
- Within the IDE, open the Example module that we created in last week's tip. By taking the previous tips to this point, your code should look as follows:
Getting definitions
Let’s take a look at the object model again. Remember that a symbol has zero or one definitions.
-
Within the loop that gets symbols, after the statement:
Debug.Print “Symbol = “ & saSymbol.Name & “ – “ & saSymbol.TypeName
type the following lines of code:
Dim mydef as SA2001.Definition Set mydef = sasymbol.Definition Debug.Print “Definition = “ & mydef.Name & “ -- “ mydef.TypeName Set mydef = Nothing
Notice that we specify the property Definition -- there is no GetDefinition – that is because there may not be a definition (as we said, there may or may not be a definition for a symbol – that is what is meant by the zero or one cardinality of the relationship). (Remember that a diagram has a collection of symbols, and a symbol may or may not have a definition.)
Let’s test the code by stepping through it. First we must be sure to close the diagram our code has opened in System Architect.
-
In System Architect, close the Use Case diagram that was opened by previously stepping through the code.
-
In the VBA IDE, click on the Reset button to reset the project.
-
Click on the Step Into button to step through the code. Notice how the encyclopedia, diagram, symbol, and definition information is printed to the Immediate window.
Now we have a definition handle called mydef. Let’s take a look at the methods and properties available with the Definition object.
-
At the end of the line of code Debug.Print “Definition = “ & mydef.Name, add the following: & “ -- “ mydef. and notice the drop-down list of available properties and functions once you type the period. There are a number of useful functions in the list.
The function GetRelatedObjects, for example, gets all relationship between objects in the repository – these are the same relationships used by the reporting system, such as “used by”, “is a”, “is defined by”, etc. Next week we'll take a look at a very useful function, GetPropertyAsCollection. For now, we will simply use the TypeName attribute to get the type of the definition.
Complete the line as follows:
Debug.Print “Definition = “ & mydef.Name & “ -- “ mydef.TypeName
Your code for this area of the module should look as follows:
- In System Architect, close the Use Case diagram that was opened by previously stepping through the code.
- In the VBA IDE, click on the Reset button to reset the project.
- Click on the Step Into button to step through the code. Notice how the encyclopedia, diagram, symbol, and definition information is printed to the Immediate window, and the type of the definition is now provided next to the name of the definition itself.
Next tip
In this tip we got the definition of a symbol; next week we'll examine using the GetPropertyAsCollection method.
Continue with the next tip, or select File, Save Example and close the VBA environment by selecting File, Close and Return to SA2001.