This is the last part in a series of tips that go through the steps of writing a VBA macro that creates SA diagram, symbols, and definitions. So far we have created a Process Chart, added two node symbols and connected them with a line symbol, and adjusted the symbol attributes and fields to add to the aesthetics of the diagram. In the last tip we created an Elementary Business Process definition.
In this tip we will create an SACollection of MetaProperties belonging to the definition and retrieve selected ones through a For…Next loop.
Retrieving definition meta data
System Architect's definitions are held inside an encyclopedia. The encyclopedia understands the structure and composition of the definition types inside the encyclopedia. The System Architect Object Model allows you to access the structure and composition of the definition types inside the encyclopedia by using the meta classes. The only way to modify the meta classes in the encyclopedia is through the USRPROPS.TXT file.
The MetaItem class
The MetaItem class allows you to return meta information about the current definition. The MetaItem properties you can retrieve are:
- Class Attribute - returns 1 for a Diagram type definition, 2 for a Symbol, and 3 for a Definition.
- TypeName Attribute - the textual name used for the definition, i.e. Class Attribute
- TypeNumber Attribute - the System Architect assigned constant number for the definition (a list of definition TypeNumbers exists in the System Architect defns.bas file)
The definition MetaProperties
Each item in the encyclopedia has associated properties. For example, when you are editing an Entity, you will notice that it has Volume, Business Description, etc. as properties. You can extract further detail about the properties for a definition type by accessing the MetaProperty class. This class opens the door to attributes that define the structure of the definition property, such as Name, Edit Type, and Default Value. A complete list of MetaProperty attributes can be found in the System Architect Object Browser.
We will take a look at the Meta Properties of the definition we created last week by retrieving the MetaProperties attribute of the MetaItem class. This will return a collection of MetaProperty classes for our definition.
-
First, we must create a collection of MetaProperty classes for the definition, "My Definition", by typing the following:
Dim metColl as SACollection Set metColl = myDefinition.MetaItem.MetaProperties
-
Now we will dimension an integer to serve as a counter, with which we will retrieve each individual MetaProperty class of the definition. Type in the following:
Dim i as integer
In order to print the collection of meta properties, we need to insert a For...Next statement. This will create a loop that will repeat itself as many times as there are meta properties in the collection.
-
To create the loop, type in the following:
For i = 1 To myColl.Count Next i
Note: The Count attribute of the SACollections class is the numeric value of the number of collection members, which we are therefore using as the last value of the counter.
Within our loop, let's print several of the MetaProperty attributes.
-
After For i = 1 to myColl.Count, insert the following code:
With myColl.Item(i) Debug.Print .Name, .EditType, .EditLength End With
Note: Using a With...End With statement allows you to only refer to the object once.
Run the macro. In the Immediate window, you should be able to see that the Debug.Print command has printed the Name, Edit Type, and Edit Length of every meta property of the definition.
Wrap up
This concludes our second series of tips on System Architect's integrated support for Microsoft Visual Basic for Applications. With VBA you can extend System Architect functionality in many ways. Through System Architect's extensive Object Model, you can access and utilize numerous attributes, methods, and fields to build macros that better suit your company's needs and specifications. By mastering VBA, you can enhance the overall precision and effectiveness offered by System Architect.