This tip is the second in a series of tips that explain how you can create and customize your own diagrams, symbols, and definitions by utilizing System Architect's integrated support for Microsoft's VBA and its development environment.
In the last tip, we created a Process Chart diagram from the encyclopedia's CreateDiagram method. This week we will add symbols to this new diagram by further accessing the System Architect Object Model.
Creating symbols on a diagram
We will use the CreateSymbol method of the diagram class to create symbols on the Process Chart we have created. We'll create two elementary business process symbols, and a Mandatory Sequence line symbol that is capable of linking the two EBP's. Let's first dimension three new variables to hold these symbols.
-
Type in the following, above the Set MyDiagram = Nothing command:
Dim saSymbol1 as SA2001.Symbol, saSymbol2 as SA2001.Symbol, saLineSymbol as SA2001.Symbol
-
Now let's use the CreateSymbol method of the diagram object to create a new elementary business process symbol on the diagram. Type in the following:
Set saSymbol1 = MyDiagram.CreateSymbol("Symbol 1",
CreateSymbol is looking for two parameters, the first (Name as String) is a text string for the name of the symbol, which we call "Symbol 1". The second parameter (SAType as Long) is looking for the symbol type.
Note: We are not restricted to the symbol types belonging to the diagram we are working with - you can add any symbol from any diagram type onto the diagram. The only restriction is the toolbar of the diagram - System Architect only permits certain symbol types to appear on each diagram's toolbar - so you can't for example, add a Use Case symbol bitmap to a Process Chart diagram's toolbar, but you can, through VBA, add a Use Case symbol to a Process Chart diagram. This would be the same as if, in System Architect, you copied a symbol from one diagram and pasted it onto another.
For our example, we want to add an elementary business process symbol. Similar to when we were creating a new diagram, we need to know the internal constant name of the symbol we wish to create. To get this information for diagrams we imported the diagrams.bas file; to get this information for symbols we need to import the symbols.bas file.
-
Right-mouse click on the Modules folder under Tutorial in the browser on the left-hand side of the VBA IDE, and select Import File.
-
In the Import File dialog, browse to the System Architect main executable directory, select the symbols.bas file, and click Open.
-
In the VBA IDE browser, under Properties, within the Alphabetic tab, highlight Module1 and rename it to Symbols.
-
Double click on the Symbols icon in the browser to view the file.
Note: Finding the particular symbol that you want is tricky. There are many symbols of similar names appearing within different System Architect diagrams of different methodologies. There are a number of process type symbols, for example. If you are unsure which symbol is the correct one for the diagram, you can reference SA Diagrams and Symbols.pdf.
Select Edit, Find and type in Symbol in the Find dialog. Click Find Next to begin searching the symbols.bas file.
Continue clicking Find Next until you arrive at the Elementary Business Process symbol pictured below.
Notice that the constant name for this symbol is ETCATELEMBUSPROC. We will add this to our code. If you wish you can highlight this name and select CTRL-C to copy it and paste it into your code in the next step. Note: copying the internal constant number into the code (in this case 445) works just the same.
-
Click on the Examples module in the VBA IDE browser to get back to the code.
-
Complete the code line started above, by typing (or pasting) in:
Set saSymbol1 = MyDiagram.CreateSymbol("Symbol 1", ETCATELEMBUSPROC)
Your code should look as follows:
Let's add another line of code almost identical to the one we have just typed, but this time make it create Symbol2.
-
Add the following line:
Set saSymbol2 = MyDiagram.CreateSymbol("Symbol2", ETCATELEMBUSPROC)
(Note: since this line is almost identical to the line we have just typed, the quick way to do this is select and copy (CTRL-C) the entire line you have just completed and paste (CTRL-V) it down again underneath, then change Symbol1 to Symbol2 for both occurences).
-
Now let's create the line symbol. Type in the following:
Set saLineSym = MyDiagram.CreateSymbol("Line",
Again, we must provide the constant name of the type of the line. We want to draw a Mandatory Sequence line. (On a Process Chart, Elementary Business Processes are connected to each other either by Mandatory Sequence lines or Optional Sequence lines.)
Double-click on the Symbols module in the VBA IDE browser, and select Edit, Find. In the Find dialog, type Mandatory Sequence and click Find Next.
We again find many Mandatory Sequence symbols used in different diagrams in System Architect. The line we want is number 428, ETCATPDMANDATORYSEQ.
Step through the code
Let's now step through the code to see how it is working. Since we have already stepped through the code, we have already created a diagram called My Diagram. If we step through now, we will get an "SAIMF" error, since the code will be trying to create a diagram that already exists.
-
In System Architect, close any open diagram and do not save it (choose No if you are presented with a dialog asking you to save the diagram).
-
In the All Methods tab of the browser, expand Process Chart. If there is a diagram named My Diagram, right-mouse click on it and select Delete.
Now you are ready to step through the code.
-
Reset the project (click the Reset button or select Run, Reset), place your cursor within the second subroutine (for example, in the Public Sub Main2(), and step into the code (click the Step Into button or select Run, Step Into).
Note how the diagram is created and the three symbols are added to the diagram.
Next tip
We have just created a Process Chart and two Elementary Business Processes and a Mandatory Sequence Line in it. In the next tip we will explore ways to position our symbols with VBA.
- Click on File, Save Tutorial and exit the VBA Editor.
Important Note: DO NOT save My Diagram when closing System Architect! An SAIMF error will appear next time you step through the code, stating that "My Diagram already exists".