This article contains tips and examples for using the Application object in Simcenter Testlab Automation. The proper name of the object is LMSTestLabAutomation.Application.
This article has the following sections: 1. Accessing Current Simcenter Testlab Instance 2. File Paths and Spaces in Startup Arguments 3. Finding DataWatches
1. Accessing Current Simcenter Testlab Instance
If calling on properties such as “Books” or “ActiveBook”, an instance of Simcenter Testlab needs to be running and a workbook needs to be open. To prevent errors from occurring if the user doesn’t have Simcenter Testlab open in the configuration expected, there are some checks that can be made:
If no running application is open, the property “Name” on the LMSTestLabAutomation.Application object will return as an empty string. Otherwise, this property returns the type of workbook currently open, i.e. “SignatureRealTimeAcquisitionFSStandard” if Simcenter Testlab Signature Acquisition is open.
If Simcenter Testlab is running but has no open projects, the property “Books.Count” on the LMSTestLabAutomation.Application object will return as zero.
For example, a program that needs a project to be open in Signature Acquisition – Advanced might use the following code:
Dim my_TL As New LMSTestLabAutomation.Application Dim desired_workbook As String = "SignatureRealTimeAcquisitionFSStandard"
If my_TL.Name = ""Then my_TL.Init("-w " & desired_workbook) ElseIf Not my_TL.Name = desired_workbook Then If my_TL.Books.Count > 0 Then Dim result AsMessageBoxResult result = MsgBox("Save current project(s)?") Select Case result CaseMsgBoxResult.Cancel Exit Sub CaseMsgBoxResult.Yes Do Until my_TL.Books.Count = 0 my_TL.ActiveBook.Save() my_TL.ActiveBook.CloseWithoutSave() Loop CaseMsgBoxResult.No Do Until my_TL.Books.Count = 0 my_TL.ActiveBook.CloseWithoutSave() Loop End If my_TL.Quit() my_TL = New LMSTestLabAutomation.Application my_TL.Init("-w " & desired_workbook) ElseIf my_TL.Books.Count = 0 Then my_TL.NewProject() End If
The “CloseWithoutSave” method is called instead of the “Close” method; “Close” requires the end user to interact with a messagebox in Simcenter Testlab, rather than in the code program, and the code freezes until the messagebox in Simcenter Testlab has been interacted with.
If the user presses “No” or “Cancel” in Simcenter Testlab, the code will resume without actually having closed the Simcenter Testlab book and without receiving any response from Simcenter Testlab as to whether the closure actually occurred. So, the above program operates the options within the code instead of through Simcenter Testlab’s external options, ensuring that the correct code paths are followed depending on the user’s response.
2. File Paths and Spaces in Startup Arguments
The “Init(ApplicationStartupArguments As String)” method can allow template files and configuration files to be used, but if there is a space anywhere in the template’s file path, the method will raise an error unless the path is delimited using quotation marks within the string.
An example of how this works:
Dim my_TL As New LMSTestLabAutomation.Application Dim my_workbook As String = "SignatureRealTimeAcquisitionFSStandard" Dim my_template As String = "C:/Documents/my template file.tpl" Dim my_config As String = "C:/Documents/my configuration file.cfg" Try My_TL.Init("-w " & my_workbook & " -t " & my_template & " -c " & my_config) ' This throws an exception; Testlab tries to find the file “C:/Documents/my” ' instead of the full path “C:/Documents/my template file.tpl” Catch ex As Exception My_TL.Init("-w " & my_workbook & _ " -t " & ControlChars.Quote & my_template & ControlChars.Quote & _ " -c " & ControlChars.Quote & my_config & ControlChars.Quote) End Try
3. Finding DataWatches
Although there is a method named “FindDataWatch” directly on the LMSTestLabAutomation.Application object, the majority of DataWatches are specific to the currently open book and can only be found through the “FindDataWatch” method on a LMSTestLabAutomation.IBook.
Dim my_TL As New LMSTestLabAutomation.Application Dim my_DW As LMSTestLabAutomation.DataWatch Dim datawatch_name As String = "Navigator_Explorer" Try my_DW = my_TL.FindDataWatch(datawatch_name) ' This raises an exception: the Navigator_Explorer DataWatch is ' only found on the IBook level, not the Application level. Catch ex AsException ' Getting a DataWatch for the active project: my_DW = my_TL.ActiveBook.FindDataWatch(datawatch_name) ' Getting a DataWatch for a particular project if multiple projects are open ' in the same application, i.e. in Testlab Desktop: Dim my_book As LMSTestLabAutomation.IBook Dim book_index As Integer = 0 my_book = my_TL.Books(book_index) my_DW = my_book.FindDataWatch(datawatch_name) End Try
Questions? Check out the resources below (and article attachments in upper right) or contact Siemens Support Center.