Simcenter Testing Solutions Simcenter Testlab Automation: Parameters

2020-10-18T01:39:50.000-0400
Simcenter Testlab

Summary


Details




Simcenter Testlab Automation: Parameters

This article contains tips for passing parameters objects in Simcenter Testlab Automation.  Example code for the different objects and parameters is also included.

This article has the following sections:
1. Application Object Parameters
2. IDatabase and PathtoTop Parameter 
3. Idata and PathWithinObject Parameter


1. Application Object Parameters

The full name of the Application object and argument string are: LMSTestLabAutomation.Application.Init(ApplicationStartupArguments As String):

Up to four types of parameters can be passed in this argument, using spaces within the string to separate the arguments.  Because of that, an argument containing a space, such as a file path, must be delimited in quotation marks (ControlChar.Quote) to be read as a single argument.
  • -w <workbook name>:  The type of workbook to initialize, i.e. Desktop Standard or Signature Acquisition.  The string used to identify a workbook can be found by looking at the names of the .cfg files the Central\Workbooks directory of the Simcenter Testlab installation path and appending “Standard” to the name; alternatively, the string can be found by opening the desired workbook and running the following two lines of code:
Dim my_TL As New LMSTestLabAutomation.Application
msgbox(my_TL.Name)
  • -a <architecture>:  The architecture to be used; the workbook name, but without the “Standard” or “Basic” extension.
  •  -t <template file>:  The full file path of a template file (*.tpl) to use when creating the new project at startup. 
  • -c <configuration file>:  The full file path of a configuration file (*.cfg) to use when creating the new project at startup.
  • -b:  Opens the workbook without creating a new project.

Some examples of how these might be used:
Dim my_TL As New LMSTestLabAutomation.Application
my_TL.Init("-w SignatureRealTimeAcquisitionFSStandard -t """C:\Documents\my template.tpl""")
  • Open Desktop without creating a new project, then open a specific file
Dim my_TL As New LMSTestLabAutomation.Application
my_TL.Init("-w DesktopStandard -b")
my_TL.OpenProject("C:\Documents\my_project.lms")
    
2. IDatabase and PathtoTop Parameter 

The IDatabase object can be used to query the contents (ie, data blocks) of a Simcenter Testlab project, sections, and runs. The full name of the IDatabase object is LMSTestLabAutomation.IDatabase.

Most of the methods and properties of the IDatabase object use a string parameter called “PathToTop” to determine which object in the database to look at.  This string is the path of the object in the project’s directory.  Unlike file paths, a forward slash rather than a backslash is used to separate each section, run, or folder name in the path, while a backslash is used to delimit the following special characters:   # / \ { }

If the path of an object is known in advance, it’s relatively straightforward:  a block named “Point1” in the folder “My Folder” in the run “Run 1” in the section “Section1” would have "Section1/Run 1/My Folder/Point1" as its PathToTop.  However, if that block were named “FRF Point1:+X/Point2:+Y”, its path would instead need a delimiting backslash:  "Section1/Run 1/My Folder/FRF Point1:+X\/Point2:+Y" would be the PathToTop.

If paths aren’t known, such as in a program that browses the project for a specific type of block, then a LMSTestLabAutomation.AttributeMap object is needed.  IDatabase objects have two propertiess that, when used together, can provide the PathToTop for each item in the project; both of these properties have an AttributeMap as their output.

SectionNames([ReturnAsPathToTop As Integer = 0]) As LMSTestLabAutomation.AttributeMap 

This returns a collection of the section name strings; setting the optional parameter ReturnAsPathToTop to 1 ensures that the returned string is in PathToTop format; however, in almost all cases the sections are the beginning of the database paths, so both outputs are identical.

ElementNames(PathToTop As String, [ReturnAsPathToTop As Integer = 0]) As LMSTestLabAutomation.AttributeMap

This returns a collection of the names of each element in a given path if ReturnAsPathToTop is 0 and a collection of PathToTops for each element in a given path if ReturnAsPathToTop is 1.  Using "" as the PathToTop will return the objects at the root level of the IDatabase, which includes the section names as well other objects such as "DescriptionArray" and "Project_Settings".

ElementType(PathToTop As String) As String

This determines what type of object is located on a particular path, providing outputs such as "Folder", "Block", or "Waterfall" depending on the given element.

An example of how these properties can be used to find the names of all blocks in a project:

Dim my_TL As LMSTestLabAutomation.Application
Dim my_database As LMSTestLabAutomation.IDatabase
Dim readout As String

Sub Browse_Root_Level()
    ' Connect to the running Simcenter Testlab application
    my_TL = New LMSTestLabAutomation.Application
           ' Get the database of the current project
           my_database = my_TL.ActiveBook.Database()
           readout = ""
           ' Get the first collection of PathToTops
           Dim section_names As LMSTestLabAutomation.AttributeMap
           section_names = my_database.SectionNames(1)
           ' Use each section name as the PathToTop to
           ' find the elements contained in the section
           For i As Integer = 0 To section_names.Count - 1
               Browse_Subfolder(section_names(i))
           Next
           MsgBox(readout)
  End Sub

  Sub Browse_Subfolder(ByVal path As String)
           ' Get the PathToTop collection for the items in the path
           Dim element_paths As LMSTestLabAutomation.AttributeMap
           element_paths = my_database.ElementNames(path, 1)

           ' Process each PathToTop in the collection
           For j = 0 To element_paths.Count - 1
               Dim this_path As String = element_paths(j)
               ' Find the type of the item
               Dim element_type As String
               element_type = my_database.ElementType(this_path)
               Select Case element_type
                   Case "Section", "Run", "Folder"
                       ' If the item contains more objects,
                       ' use it as the new PathToTop
                       ' and browse deeper into the object

                       Browse_Subfolder(this_path)
                   Case "Waterfall"
                       ' If the item is a waterfall, which is a
                       ' hierarchial endpoint collection of blocks,
                       ' add the label of each of its blocks to the readout.

                       Dim my_waterfall As LMSTestLabAutomation.IWaterfall
                       my_waterfall = my_database.GetItem(this_path)
                       For k = 0 To my_waterfall.BlockCount - 1
                           readout &= my_waterfall.Block(k).Label & vbNewLine
                       Next
                   Case "Block"
                       ' If the item is a block, which is a
                       ' hierarchial endpoint, add its label
                       ' to the readout.

                       Dim my_block As LMSTestLabAutomation.IBlock2
                       my_block = my_database.GetItem(this_path)
                       readout &= my_block.Label & vbNewLine
               End Select
           Next
   End Sub

3. Idata and PathWithinObject Parameter

Similar to the PathToTop parameter of an IDatabase, the PathWithinObject is used to navigate the directory of properties within an IData object. The full name of the IData object is LMSTestLabAutomation.IData.Item(PathWithinObject As String).

There is a difference between IDatabase and IData: While each item in the AttributeMaps returned by the IDatabase properties SectionNames() and ElementNames() is a string, the AttributeMap property of an IData can be a collection of varying and complex data types, such as IScalarVariables, IQuantities, or other IDatas containing nested properties.  

To get the path for each property, the KeyNames property of that AttributeMap must be used – this returns another AttributeMap, but similar to the AttributeMaps of the IDatabase, this is a simple collection of the path strings for each property.

The optional parameter ReturnAsPathToTop of the IDatabase methods does not exist here; only the name of the current property is returned, not the full PathWithinObject.

An example of how to find the paths in an IData object and the types of each item in the path is shown below. Visual Basic keywords in dark blue, object types in light blue, comments in green, input text strings in red:

       Dim my_TL As LMSTestLabAutomation.Application
       Dim my_IData As LMSTestLabAutomation.IData
       Dim readout As String

       Sub Start_Browse()
           ' Connect to the running Simcenter Testlab application
           my_TL = New LMSTestLabAutomation.Application
           ' Get a DataWatch port to look at
           Dim my_DataWatch As LMSTestLabAutomation.DataWatch
           Dim dw_name As String = "\{Project\}\/\{Section\}\/Settings\/ChannelList"
           my_DataWatch = my_TL.ActiveBook.FindDataWatch(dw_name)
   
           my_IData = my_DataWatch.Data
           readout = ""

           ' Get the first collection of KeyNames
           Dim first_keys As LMSTestLabAutomation.AttributeMap
   
           ' Use each key name as the PathWithinObject to
           ' find the elements contained in the property

           For i As Integer = 0 To first_keys.Count - 1
               Browse_Attributes(first_keys(i))
           Next
           MsgBox(readout)
       End Sub

       Sub Browse_Attributes(ByVal path As String)
           ' Get the KeyName collection for the items in the path
           Dim new_IData As LMSTestLabAutomation.IData
           new_IData = my_IData.AttributeMap.Item(path)

           If new_IData.AttributeMap.Count = 0 Then
               ' If this is an endpoint, add the PathWithinObject
               ' and the IData type to the readout string

               readout &= path & " " & new_IData.Type & vbNewLine
           Else
               Dim new_keys As LMSTestLabAutomation.AttributeMap = new_IData.AttributeMap.KeyNames
               For j = 0 To new_keys.Count - 1
                   ' Browse the sub-properties of the property
                   Browse_Attributes(path & "/" & new_keys(j))
               Next
           End If
       End Sub

Questions?  Check out the resources below (including article attachments) or contact Siemens Support Center.

Simcenter Testlab Automation resources:

KB Article ID# KB000043409_EN_US

Contents

SummaryDetails

Associated Components

Simcenter Testlab Digital Image Correlation Testlab Environmental Testlab Acoustics Testlab Data Management Testlab Desktop Testlab Durability Testlab General Acquisition Testlab General Processing & Reporting Testlab Rotating Machinery & Engine Testlab Sound Designer Testlab Structural Dynamics Testlab Turbine