This is the fourth part in a series of tips, in which we are exploring System Architect's ability to customize its application behavior and extend application functionality through its integrated support of Microsofts VBA. We have already created a Process Chart diagram and three symbols by utilizing the SA Object Model, and last week we connected two Elementary Business Processes with a Mandatory Sequence Link.
In this tip we will show how you can position symbols on a diagram in VBA. This is especially useful if you importing symbols from another diagram. By setting the XPos and YPos attributes in VBA, you can prevent the symbols from being imported on top of each other in the new diagram.
So far, our code in the subroutine looks as follows:
Positioning the symbols on the diagram
Let's now use the XPos and YPos properties of the symbol object to place one of the symbols on the diagram.
-
In the previous exercise, you should have stepped to the Set MyDiagram = Nothing command. Set a breakpoint at this Set MyDiagram = Nothing line (click your cursor in the left margin so that a red bullet is placed in the margin).
-
In the Immediate window, type the following:
SaSymbol1.XPos = 200
and hit Enter.
Notice how Symbol1 is moved on the diagram.
-
Experiment with this command a little - change 200 to 1000 and hit Enter, and notice where the symbol is placed on the diagram. Change the XPos number to 350, and hit Enter again.
Now let's try the YPos command.
-
In the Immediate window, under the line you just typed, add a new line - type:
SaSymbol1.YPos = 400
and hit Enter.
Notice how Symbol1 is moved on the diagram.
-
Change theYPos number to 200, and hit Enter again. See where the symbol has moved on the diagram.
Note: As mentioned previously, the Immediate window is a great place to experiment with code, before actually adding it to your real code and having to step through the code to see the results. It gives you immediate feedback.
-
Cut the lines out of the Immediate window (select both lines and hit CTRL-X), and paste (CTRL-V) them into your code, above the line Set MyDiagram = Nothing.
Next tip
Setting the location of the symbols in our diagram is just one example of using the Symbol Class attributes to enhance the design and add utility to the diagram. In the next tip, we will experiment more with the aesthetic attributes of symbols in our diagram.
- 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.