This tip is the sixth 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 created a loop to get information on a collection of diagrams. In this tip we'll filter the list of diagrams to get specific ones.
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:
Filtering the list of diagrams
So far we have acquired and printed (to the Immediate window) all diagrams in the currently open encyclopedia. Now let’s get a particular diagram type – this will often be the case when building macros, when you only want to deal with a particular diagram type such as ER diagrams, Process Charts, Use Cases, etc.
-
Go back to the line that reads:
Set myDiagrams = SA2001.Application.Encyclopedia.GetAllDiagrams
Delete the ‘.GetAllDiagrams’ syntax at the end of this statement, and replace it with ‘.GetFilteredDiagrams’, as shown below (be sure to type an open parenthesis at the end of the statement):
Set myDiagrams =SA2001.Application.Encyclopedia.GetFilteredDiagrams(
Once you type in the open parenthesis, Intellisense will provide you with a pop-up that tells you the parameters and the parameter types for this method. There are two parameters: WildCardName, with a parameter type of String, and SAType, with a parameter type of Long.
For WildCardName, we must type in the name of the diagram as a text string. We will provide a null name (ie, nothing); this will get any diagram.
-
Type in an open and closed quote with a comma, as shown:
SA2001.Application.Encyclopedia.GetFilteredDiagrams("",
Now the SAType As Long parameter (which Intellisense makes bold) must be specified. Every diagram type in System Architect is known by a name and a number. For example, the diagram type “Entity Relation” is known by the type name “Entity Relation” and an internal number, 4.
Getting the diagram type's internal name and number
Each diagram's type and internal number is specified in a file called Diagrams.bas, provided in System Architect's main executable directory. For ease of use, we can insert a module into our VBA project and import this file so that it's information is readily available.
-
Right-mouse click on the Modules selection in the left-hand window of the VBA IDE, and select Import File.
-
Browse to the System Architect main directory and select the Diagrams.bas file, and click Open.
-
In the lower left-hand corner of the VBA IDE window, rename the new module Diagrams.
-
Double-click on the Diagrams module in the upper left-hand window to open the module and examine it. This file, Diagrams.bas, contains a list of all diagrams with their internal name and number. It includes, at the end of the list, user diagrams that are provided so that users may create their own diagram types via USRPROPS.TXT (to create their own diagram type, a user renames one of the user diagrams).
For our example, we need either the diagram type’s internal name (starts with ‘GT’) or internal number.
Note: You may either use the diagram type’s internal name or number. It is preferred to use the name, since it is less apt to change than the number.
-
In the left-hand pane, double-click on Example to get back to the code.
-
After the comma that we previously typed in, type in GTOOUSECASE and close the parenthesis, so that the code looks as follows:
SA2001.Application.Encyclopedia.GetFilteredDiagrams(“”,GTOOUSECASE)
-
Reset the project (click the Reset button) and step through the code (click the Step Into button). Notice that two Use Case diagrams are printed to the Immediate window.
Next tip
In this tip we filtered the list of diagrams to get specific ones. In the next tip we'll use the fact that we have a diagram, to get information on the diagram, and the symbols drawn on it.
- Continue with the next tip, or select File, Save Example and close the VBA environment by selecting File, Close and Return to SA2001.