This tip is the eighth 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 a list of all symbols on a diagram. In this tip we'll get information about those symbols.
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 information on symbols
Certain information about symbols (for example, name, typename, auditID, etc) is obtained directly from the symbol. To obtain diagrammatic information, however, you must have the diagram open. Diagrammatic information includes its color, size, positioning on the diagram, etc.
Let’s take a look at some of the properties of symbols that we can get at directly.
- First, place a ‘halt’ on the line Debug.Print "Symbol =" & saSymbol.Name & “ – “ & saSymbol.TypeName by clicking in the grey, left-hand margin. A red bullet will appear in the margin.
- Step through the code (clicking the Step Into button on the menu) until you highlight this line.
- Place your cursor in the Immediate window and type: ? sasymbol.Name and hit Enter. You will see the name of the current symbol printed in the Immediate window.
? sasymbol. UpdateDate
and hit Enter. You will see the date when this symbol was last changed in the Immediate window.
Let’s try one more:
and hit Enter.
You will get an error message that tells you that you have a ‘Run-time error … Diagram is not open’.
System Architect is telling you that you must have a diagram open to get at this property (whereas the previous properties are all carried in the symbol). Let’s adjust our code to open a diagram.
Opening a diagram
We will use the diagram object’s show and hide functions to open and close the diagram.
In your code, after the statement in which you get the diagram,
Set myDiagram = myDiagrams(1)
add the following statement:
(be careful to type myDiagram, not myDiagrams)
This will open the diagram. After the loop to get all symbols, we must close the diagram.
After the line Next i, add the line:
Your code should look as follows:
Let’s now step through the code from the beginning of our program.
- Click the Reset button (rectangle) in the VBA toolbar (or select Run, Reset).
- Click on the Step Into button to begin walking through the code. Notice that stepping through the line myDiagram.Show opens the Use Case diagram that we specified in System Architect.
Continue stepping into the code, walking the loop through symbols until the symbol Reject Customer Because of Bad Credit – Use Case appears in the Immediate window.
Now let’s get diagrammatic properties of this symbol.
In the Immediate window, underneath the statement Symbol = Reject Customer Because of Bad Credit -- Use Case, type the following:
and hit Enter.
Notice that the ASCII code for the color is printed in the Immediate window.
and hit Enter.
You will see the symbol's position from the top left-hand corner in hundreds of an inch (so 587 = 5.87 inches). Here we are reading the position of a symbol – remember that everything that we read we can also use to specify something; in this case, the Xpos and Ypos properties can be used to position symbols on a diagram if we were writing a macro that created a diagram automatically.
In this tip we got information on symbols, then opened a diagram and got diagrammatic information on a symbol. In the next tip we'll get the definition of a symbol.
- Continue with the next tip, or select File, Save Example and close the VBA environment by selecting File, Close and Return to SA2001.