System Architect's integrated support for Microsoft's Visual Basic for Applications and its development environment is a powerful feature that allows users to control SA's environment programmatically and develop many customizable solutions. This multi-part Tip of the Week series will explore the creation and manipulation of diagrams, symbols, and definitions that can be done within the System Architect VBA Editor. This behind-the-scenes, customizing functionality enables users to modify the way System Architect works to match their companies' business rules and processes, as well as add features to SA that are not available out of the box.
In our last VBA Tip series, Creating a VBA Macro, we introduced System Architect's support for VBA. Through the extensive eleven-part tip, we created a simple VBA Macro, while at the same time, explored the System Architect Object Model and its respective classes, attributes, and methods.
If you are unfamiliar with building a VBA macro and/or System Architect's Object Model, it is recommended that you go through the previous VBA Tip series, Creating a VBA Macro.
We left off from that Tip series with the following code:
Creating diagrams
Let's add a new subroutine to our module that will create a diagram in System Architect.
- In the VBA IDE, select Insert, Procedure.
- In the Insert Procedure dialog, type Main2 as the name of the new procedure. (Keep its Type as Sub and its Scope as Public.)
Let's dimension a variable called sa as an sa2001 application. At this point, our module knows we are working with the application of sa2001, since we declared it at the top of the first subroutine. We really only need to dimension sa as application; however it is good practice to specify the 'sa2001' before 'application', since this will enable our code to be portable to other applications.
-
Type in the following to dimension the sa variable, set it to the application, and free memory by setting it to nothing at the end:
Dim sa As SA2001.Application Set sa = New SA2001.Application
Set sa = Nothing
Let's now dimension a new variable, myDiagram, and use the encyclopedia's CreateDiagram method to create a Process Chart diagram.
-
Dimension the new myDiagram variable by adding the following to the Dim sa As SA2001.Application:
Dim sa As SA2001.Application, MyDiagram As SA2001.Diagram
Now let's use the Encyclopedia object's CreateDiagram method to create a new Process Chart diagram. We'll call it "My Diagram".
-
Type in the following:
Set MyDiagram = sa.Encyclopedia.CreateDiagram("My Diagram",
As you type in the final comma, you see from the Intellisense pop-up that you need to specify the type of diagram for the CreateDiagram's second parameter - SAType as Long.
-
To get the internal constant name of the Process Chart's type, you must import the System Architect diagrams.bas file, which contains a list of every diagram's internal name and number, from the File, Import File menu. Double-click on the Diagrams module in the VBA IDE browser (upper left) to view the diagrams.bas file. Search the right-hand column for Process Chart. Once you find it, note that the diagram constant and number is GTCATPROCESSFLOW = 89.
-
Finish the Set MyDiagram line by typing in the following:
Set MyDiagram = sa.Encyclopedia.CreateDiagram("My Diagram", GTCATPROCESSFLOW)
Let's test it and create a diagram.
- Make sure all System Architect diagrams are closed, 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).
- Notice that a new Process Chart diagram is created and opened in System Architect. By default it has a first swimlane on it (two horizontal lines in the upper left-hand corner of the diagram workspace.
Model and packaged based diagrams
Models and packages are used to facilitate and denote groupings of items (diagrams and definitions) as belonging to a particular model or package. This allows the re-use of commonly shared definitions among different models and packages while also allowing for the re-use of item names. The following is a list of all SA diagrams that are either model or packaged based.
If you are creating a diagram that is model or packaged based, then you MUST specify a model or packaged through the relevant property, SetProperty. For example:
Call myDiagram.SetProperty "Model","Sales"
Or
Call myDiagram.SetProperty "Package","Sales"
Note: that by setting the Model or Package property, those items now belong to that particular model or package.
Next tip
In the next part of this VBA Tip series we will add symbols to our newly created Process Chart diagram.