CONTACT US image
Welcome Company Services Products Partners Support
Simplification Platform Transport™ ServerInsight™
 

Extending Transport™ Architect with VBA

How Do I add my own routines to VBA? 
How Do I Get started declaring my Transport Architect Object?
How do I accesses the Classes showing on my Transport Architect screen?
How do I put a new class in my document?
How can I paste a portion of my diagram into Word using VBA?
How Do I access States from my state diagram in VBA?
How do I use the GetNext feature in collections?
How do I access related classes such as Base Classes of my Class?
How do I access relations leaving or entering the Class?
How do I batch the existing scripting in Transport Architect from VBA?
How do I Trigger my own code on Transport Architect Events?
How do I Draw States and Transitions using VBA?
How do I Do My Own Reverse Engineering using VBA?
How do I Do Extract descriptions from use cases in use case diagrams?

NOTE: The COM Interface is Accessible from any COM-enabled Language Including VB, VB.NET, C#, etc.


How Do I add my own routines to VBA?

 

 

 

 

 


back to top
Adding new routines to the vba library is fairly straightforward:
1. Go into the VBA Editor From the Utilities menu in Transport Architect
2. Click on the Transport Architect_Macros Project title
3. Insert a module from the Insert Menu
4. Change the name of the module in the properties window by clicking on the name of the module and typing in your own name
5. Start writing your subroutines in the editor window.
How Do I Get started declaring my Transport Architect Object?

 

 

 

 

 


back to top
If you are using VBA within Transport Architect, You can use the global ActiveDocument pointer to access all of your information in the current active document so you don't really need to declare a Transport Architect object. However you could declare a reference to your active document as follows:

Dim wcDocument As With_Class.Document
Set wcDocument = With_Class.ActiveDocument

How do I accesses the Classes showing on my Transport Architect screen?

 

 

 

 

 

 

 

 

 

 


back to top
You can cycle through all the classes out of the current document by declaring a class collection and then cycling through all the classes in the current document. The following Code prints the name of all the classes in the document

Dim ClassList As With_Class.Classes
Dim CurrentClass As With_Class.Class
Dim iCount As Integer
Dim j As Integer

Set ClassList = wcDocument.Classes
iCount = ClassList.Count
For j = 1 to iCount
Set CurrentClass = ClassList.Item(j)
Print CurrentClass.Name
Next j

How do I access Attributes and Operations in my Class?


 

 

 

 

 





back to top
To access an Attribute, you have to access the attribute collection in the class. Operations are accessed in the same way. The following code gets the last Attribute in the attribute list and prints its type:

Dim CurrentAttribute As With_Class.Attribute
Dim AttributeList As With_Class.Attributes
Dim iCount As Integer;
Set AttributeList = CurrentClass.Attributes
iCount = AttributeList.Count
Set CurrentAttribute = AttributeList.Item(iCount)
Print CurrentAttribute.Type

How do I put a new class in my document?



 

 

 

 

 


back to top
Transport Architect has the ability to draw classes and populate them from VBA.You just need to specify the coordinates of the class and its name and an object to the class is returned. You can then add attributes and operations using the new object The Code below makes a package Called AnimalPack and adds a class Dog . It then adds an attribute color to dog.
Dim CurrentPackage As With_Class.Package
Dim CurrentClass As With_Class.Class
Set CurrentPackage = CurrentDocument.NewPackage(180, 560, "AnimalPack")
Set CurrentClass = CurrentPackage.NewClass(100, 250, "Dog")
CurrentClass.NewAttribute("color")
How can I paste a portion of my diagram into Word using VBA?

 

 

 

 

 


back to top

You can use the method CopyRegionToClipBoard in the Document interface to clip a region of your diagram. You just specify the rectangular coordinatesyou want to clip. The example below clips a region of about 7 x 7" of the first page and pastes it into word:
Dim wcDocument As With_Class.Document
Dim ThisWord As Word.Application
Dim newDoc As Object
Set wcDocument = CurrentDocument
Set ThisWord = CreateObject("Word.application")
Set newDoc = ThisWord.Documents.Add
wcDocument.CopyRegionToClipBoard 0, 0, 500, 500
ThisWord.Selection.Paste
How Do I access States from my state diagram in VBA?

 

 

 

 

 


back to top

Accessing states is done in much the same way as accessing classes.  The document has a state collection called states, just like it has a classcollection. The code below cycles through all the states and prints out a state Description:
Dim StateList As With_Class.States
Dim CurrentState As With_Class.State
Dim iCount As Integer Dim j As Integer
Set StateList = wcDocument.States
iCount = StateList.Count
For j = 1 to iCount
Set CurrentState = StateList.Item(j)
Print CurrentState.Description
Next j
How do I use the GetNext feature in collections?

 

 

 

 

 

back to top

Transport Architect provides 2 ways to cycle through collections. The first we've seen is Using Item(I), but the other way, which turns out to be more efficient, is using GetNext. The way GetNext is implemented is you must "Restart" your collection each time you use it and then detect the last element by  using "IsLast". Below is an example of cycling through classes using the GetNext feature:
Dim ClassList As With_Class.Classes
Dim CurrentClass As With_Class.Class
Dim strClass As String
Set ClassList = CurrentDocument.Classes
ClassList.Restart
While (ClassList.IsLast = False)
Set CurrentClass = ClassList.GetNext
strClass = CurrentClass.Name
Print strClass
Wend
How do I access related classes such as Base Classes of my Class?

 

 

 

 

 

back to top

Related classes, that is classes connected with a relationship line, can be accessed by using the relation class collections SuperClasses, AssociationClasses, AggregationClasses, and Dependency Classes. Below is an example that prints out all base classes of the current class:
Dim BaseList As With_Class.Classes
Dim iCount As Integer
Dim j As Integer
Dim CurrentBaseClass As Class
Set BaseList = CurrentClass.SuperClasses
iCount = BaseList.Count
For j = 1 to iCount
Set CurrentBaseClass = BaseList.Item(j)
Print CurrentBaseClass.Name
Next j
How do I access relations leaving or entering the Class?


 

 

 

 

 

back to top

Relationships can be accessed from a Class through the RelationsIn andRelationsOut property: Below is an example that prints the role name of all aggregate relations Leaving the CurrentClass:
Dim RelationList As With_Class.Relationships
Dim CurrentRelation As With_Class.Relationship
Dim iCount As Integer
Dim j As Integer
Set RelationList = CurrentClass.RelationsOut
iCount = RelationList.Count
For j = 1 to iCount
Set CurrentRelation = RelationList.Item(j)
If CurrentRelation.Type == "Aggregation" Then
Print CurrentRelation.RoleName
End If
Next j
How do I batch the existing scripting in Transport Architect from VBA?

 

 

 

 

 

 

back to top

You can actually run Transport Architect's internal scripting at the class level using the VBA Macro property RunClassScript. You just need to pass the class object, the name of the script and the extension you wish to tagonto the final file output name. For example RunClassScript(CurrentClass.Name,"vcfunc0.sct", ".cpp") would generate foo.cpp using The vcfunc0.sct scriptif the CurrentClass.Name is foo. Below is an example that cycles through all classes using the vcfunc0.sct script:
Dim ClassList As With_Class.Classes
Dim CurrentClass As With_Class.Class;
Dim iCount As Integer
Dim j As Integer
Dim strScriptDir As String
strScriptDir = "c:\program files\wc98\scripts\"
Set ClassList = wcDocument.Classes
iCount = ClassList.Count
For j = 1 to iCount
Set CurrentClass = ClassList.Item(j)
wcDocument.RunClassScript(CurrentClass.Name, strScriptDir + "vcfunc0.sct","*.cpp")
Next j
How do I Trigger my own code on Transport Architect Events?

 

 

 

 

 


back to top

Transport Architect (version 5.03) has several events that you can utilize to insert your own code after these events occur. There are events like ClassSelected, AttributeChanged, ClassMoved. To utilize the events in Transport Architect, double click on the ThisDocument in wc98 objects in the VBA Editor. Click on the combo box on the upper left hand corner that says General and choose Document. The events will appear on the right side and you can choose the event function you want from this list. The VBA IDE will automatically insert the function for you. Below is the code for the operationchanged event. This will be triggered after the user makes changes to their operation in an operation dialog. Note that the event supplies the operation that has been changed:

Private Sub Document_OperationChanged(ByVal TheChangedOperation As Object)
MsgBox("The Operation that was changed was " & TheChangedOperation.Name)
End Sub

How do I Draw States and Transitions using VBA?

 

 

 

 

 

 

 

 

 

 


back to top

Transport Architect 5.03 allows you to draw states and transitions. 5.03 also provides some global constants so you can pick which state you are going to draw:
Dim wcDocument As With_Class.Document
Dim state1 As With_Class.State
Dim state2 As With_Class.State
Dim trans1 As With_Class.Transition
Dim trans2 As With_Class.Transition
Set wcDocument = With_Class.ActiveDocument
wcDocument.ShowView (wcvState)
Set state1 = wcDocument.NewState(100, 20, "ON", wcsInitial)
Set state2 = wcDocument.NewState(100, 200, "OFF", wcsTerminal)
Set trans1 = wcDocument.NewTransition(state1, state2, "switchedOn", "temp > 10", "turnOn")
Set trans2 = wcDocument.NewTransition(state2, state1, "switchedOff", "temp < 20", "turnOff")

as several events that you can utilize to insert your own code after these events occur. There are events like ClassSelected, AttributeChanged, ClassMoved. To utilize the events in Transport Architect, double click on the ThisDocument in wc98 objects in the VBA Editor. Click on the combo box on the upper left hand corner that says General and choose Document. The events will appear on the right side and you can choose the event function you want from this list. The VBA IDE will automatically insert the function for you. Below is the code for the operationchanged event. This will be triggered after the user makes changes to their operation in an operation dialog. Note that the event supplies the operation that has been changed:

Private Sub Document_OperationChanged(ByVal TheChangedOperation As Object)
MsgBox("The Operation that was changed was " & TheChangedOperation.Name)
End Sub

How do I Do My Own Reverse Engineering using VBA?

 

 

 

 

 

back to top

This is probably to in depth to discuss in a few brief statements so we have provided an example. Transport Architect  comes with a Parser object that eases creation of your own reverse engineering scripts and addins. The example we provide is how to reverse engineer a perl class using Transport Architect. This same example can be applied to reversing other languages
How do I Do Extract descriptions from use cases in use case diagrams?

 

 

 

 

 


back to top

Transport Architect adds a bunch of new diagrams where you can access components in the diagram using vba collections. Below is an example for looping through use cases and printing out descriptions in a message box
Dim Diagram As With_Class.UseCaseDiagram
Dim MyCases As With_Class.WCCollection
Dim MyCase As With_Class.Shape
Set wcDocument = With_Class.ActiveDocument
Set Diagram = wcDocument.UseCaseDiagrams.Item(1)
Set MyCases = Diagram.Cases
MyCases.Restart
While (MyCases.IsLast = False)
Set MyCase = MyCases.GetNext
MsgBox (MyCase.Description)
Wend
End Sub
SITE MAP   PRIVACY option image   CONTACT US image