This program looks for the following directory path (Figure 1) within the example project:
Figure 1: Path and data block used in example program and project.
The example.lms project is attached at the end of this article The example program illustrated in this article uses Visual Basic.
Program Overview
When a button on the Visual Basic form is clicked, the following subprogram is run.
First, it links to Simcenter Testlab by instantiating the LMSTestLabAutomation.Application object named “TL,” and if this object does not connect to a running instance of the program, the property "TL.Name" returns an empty string. In this case, it starts up the Desktop application; otherwise, it opens an existing project file named “example.lms” located at D:\LMSData.
Once the project is open, it accesses the database of the currently open project using the ActiveBook.Database property on the Application object.
Depending on whether the desired project file is open at the moment, there are different ways to access a database:
The file is not currently open: The database of any .lms file on the computer can be accessed through the Database(ProjectPathName As String) property on the Application object, but this should be used with caution: the database does not close on its own when the program ends or when the Simcenter Testlab application is closed, so until the Quit() method is called on an Application object or the computer is logged off, that file can only be opened in “Read-Only” mode, similarly to a shared file being used by another user at the moment, and the database cannot be accessed by any other IDatabase objects until it is closed.
The file is currently open: use the Database property of an IBook, which can be obtained through an Application object’s ActiveBook property or from the IBook collection in the Application object’s Books property. Calling the Database property directly from the Application object rather than from an IBook object Database property will raise an error if the file is currently open, because the database is already in use as a property of one of the active Application object’s books; with “TL” as the Application object as in this example, TL.ActiveBook.Database or TL.Books(book_index).Database would instead be the correct way to access the current project or the book_indexth project, respectively, while TL.Database(filePath) would raise an error. Because the database is a part of an open project, the issue of “Read-Only” locking mentioned above does not occur.
Once the database is accessed, a data block is retrieved from the data. The parameter “dataPath” is an absolute path through the project’s directory, and if this path does not exist, an error is raised.
The program then accesses the Desktop application’s Navigator tab’s display panel manager through the DataWatch “Navigator_DataViewing_PictureManager.” DataWatches are specific ports provided for automation that each handle certain tasks or parameters; depending on the type of Simcenter Testlab workbook open, there can be hundreds to thousands of different DataWatches available.
The Data property on a DataWatch can return different types of objects, depending on which DataWatch is being used. The Navigator_DataViewing_PictureManager returns an IPictureManager object, which is an interface for adding and managing pictures.
The AddPicture(LayoutName As String) method on the IPictureManager object both creates a new picture with the designated layout (i.e. “1x2”, “FrontBack”, “Matrix-Heatmap”) and returns a reference to that picture as an IPicture object.
The Display(Index As Integer) property on an IPicture object returns a display of the picture as an IDisplay using a zero-based index; in a 1x2 display, Display(0) returns the top display while Display(1) returns the bottom display.
See Figure 2 for a visual definition of IPictureManager, IPicture, and IDisplay.
Figure 2: Visual definition of IPictureManager, IPicture, and IDisplay of a 1x2 Simcenter Testlab display.
The AddData(Target As Integer, Data As LMSTestLabAutomation.IData) method on an IDisplay object adds the given data to the given target location. IData is a general data type that encompasses many of the more specific types, such as IBlock2, so different displays (i.e. FrontBack, Waterfall, Numeric) can get different types of input. The Target parameter, also a zero-based index, indicates where to put the data within a display – in a FrontBack display, Target=0 would put the data in the Front display, Target=1 would put the data in the Back display, Target=2 would put the data in the Back 2 display, and so on.
Figure 3 illustrates the example data block added to the top display of a 1x2 Simcenter Testlab display.
Figure 3: Data block added to the top display of a 1x2 Simcenter Testlab display
Finally, the ClearData(Target As Integer) method on the IDisplay object is called, removing the data from the target area as described above.
Program Code
Example Visual Basic code for displaying data block. Visual Basic keywords in dark blue, object types in light blue, comments in green, input text strings in red.
Public ClassForm1
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click 'Examples: used project file and path to data in project file Const filePath As String = "D:\\LMSData\\example.lms" Const dataPath As String = "ordertracking/Run 1/Fixed sampling/Runup/Sections/Frequencies/Frequency 25.00 Hz Point5"
'Declarations of the used objects Dim TL As LMSTestLabAutomation.Application Dim database As LMSTestLabAutomation.IDatabase Dim datawatch_pictManag As LMSTestLabAutomation.IDataWatch Dim pictManag As LMSTestLabAutomation.IPictureManager Dim myPicture As LMSTestLabAutomation.IPicture Dim myBlock As LMSTestLabAutomation.IBlock2 Dim myDisplay As LMSTestLabAutomation.IDisplay
Try 'Open Test.Lab to the Desktop Workbook, if not already opened TL = New LMSTestLabAutomation.Application If (TL.Name = "") Then TL.Init("-w DesktopStandard" + filePath) Else TL.OpenProject(filePath) End If