The data in the display is accessed to determine what quantity conversions may need to be performed on the cursor’s X-value position
A cursor is created at the desired location
The cursor is moved by duplicating it to the new position and removing the original
The program looks a for a display in Simcenter Testlab Navigator that already contains at least one data curve as shown in Figure 1.
Figure 1: Simcenter Testlab FrontBack display with single curve.
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.” If no instance of the program is running, it starts the Desktop application and opens the specified file; otherwise it connects to the running instance, whether Desktop, Signature Acquisition, or another workbook, and opens the project file in that workbook.
Once the project is open, it accesses the IPictureManager object returned as the IData of the “Navigator_DataViewing_PictureManager” DataWatch on the current project’s IBook. This DataWatch provides an interface for adding and managing pictures.
The program accesses the first display of the first picture; the indices are zero-based. The Cursor Manager of this display is then retrieved as an ICursorManager object.
The next step is to create a cursor at a desired location. However, the input parameter for cursor position is in MKS units, so this input should be scaled by a quantity conversion prior to entering it as a parameter if the user-unit value differs from the MKS value. To find the user-unit of the data, the data block currently in the display is retrieved using its zero-based indices; passing the parameters (1, 0) indicates the second target’s first data block, which in this case yields the first curve on the back axis of a Front-Back display. Once this data is obtained, the UserToMKSValue(ByVal Quantity As LMSTestLabAutomation.IQuantity, ByVal ac_UserValue As Double, [ac_bBuiltIn As Integer = 0]) As Double method of the UnitSystem is called using the data block’s X-axis quantity and the desired location.
The cursor is created using the ICursorManager object’s method CreateSingleCursor(Axis As LMSTestLabAutomation.CONST_EnumAxisType, Position As Double, [CursorProperty As LMSTestLabAutomation.IData]) As LMSTestLabAutomation.ISingleCursor. This creates an ISingleCursor object for the desired axis, specified position, and optional properties that can be specified in a LmsHq::DataModelVI::PropertyFDisp::CBufferICursorProperty IData; however, the ISingleCursor exists only in the Visual Basic program and has not yet been added to the Simcenter Testlab project.
To bring this cursor into the project, the ICursorManager object’s method Add2(Cursor As LMSTestLabAutomation.ICursor) As String is called, which places a new cursor into the display using the properties and location of the cursor parameter and returns a generated string ID that can be used later for removing the cursor or accessing its DataWatch.
The result of placing the cursor in the display is illustrated in Figure 2.
Figure 2: Simcenter Testlab FrontBack display with single curve and cursor.
Optionally, the Add(ID As String, Cursor As LMSTestLabAutomation.ICursor) As String can be used to designate a custom ID; this method returns the full identification name, i.e. using “My Cursor” as the ID parameter, the method returns “AutomationCursorManager/My Cursor” as the actual ID of the new cursor. The IDs of cursors created through automation can also be found as the AttributeMap KeyNames of the IData of the “AutomationCursorManager” DataWatch.
The ICursor object used as a parameter in either of the above methods does not connect to the cursor created in the display; any changes to the ICursor object will not affect any cursors in the Simcenter Testlab application that were created using that ICursor. Editing an existing cursor in the display can be done one of two ways – removing the existing cursor and replacing it with an ICursor object with the desired new attributes, or editing the existing cursor using a DataWatch port. Only cursors created through automation can be manipulated.
The first method begins by editing the ICursor object via its SetPosition(ByVal Position As Double) method, which returns a new ICursor object identical to the first but with the new position. The ICursorManager is then used to remove the old cursor and add the new cursor, again storing the new ID string in a variable as shown in Figure 3.
Figure 3: Display with cursor moved.
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"
'Declarations of the used objects Dim TL As LMSTestLabAutomation.IApplication Dim datawatch_pictManag As LMSTestLabAutomation.IDataWatch Dim pictManag As LMSTestLabAutomation.IPictureManager Dim myDisplay As LMSTestLabAutomation.IDisplay Dim myCursorManager As LMSTestLabAutomation.ICursorManager Dim myCursor As LMSTestLabAutomation.ISingleCursor
'Open Simcenter Testlab 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
'Retrieve first display myDisplay = pictManag.Picture(0).Display(0)
'Retrieve the CursorManager myCursorManager = myDisplay.CursorManager
'Most of the times the units are expressed in UserUnits like RPM, ... 'These have to be converted to mks units: example 1500 rpm converted to mks 'First argument of get_Data is the target (see documentation) Dim dat As LMSTestLabAutomation.IBlock2 = myDisplay.Data(1, 0) Dim position AsDouble = TL.UnitSystem.UserToMKSValue(dat.XQuantity(0), 1500)
'Create a SingleCursor myCursor = myCursorManager.CreateSingleCursor(LMSTestLabAutomation.CONST_EnumAxisType.X, position, Nothing)
'Add the cursor to the Picture and record the generated ID Dim myCursorID AsString = myCursorManager.Add2(myCursor)
'Change the position using the ID to remove and replace the cursor position = TL.UnitSystem.UserToMKSValue(dat.XQuantity(0), 2000) myCursor = myCursor.SetPosition(position) myCursorManager.Remove(myCursorID) myCursorID = myCursorManager.Add2(myCursor)
'Change the position using the ID to find a DataWatch port position = TL.UnitSystem.UserToMKSValue(dat.XQuantity(0), 3000) Dim CursorDW As LMSTestLabAutomation.DataWatch = TL.ActiveBook.FindDataWatch(myCursorID) Dim newCursor As LMSTestLabAutomation.ISingleCursor = CursorDW.Data newCursor = newCursor.SetPosition(position) CursorDW.Data = newCursor
MessageBox.Show("Done") End Sub End Class
Questions? Check out the resources below (and example files attached upper right) or contact Siemens Support Center.