Accessing File Metadata From Analysis Automation Procedure Script

Updated Mar 1, 2024

Environment

Software

  • DIAdem
  • SystemLink Server
  • SystemLink TDM Analysis Add-On

This article demonstrates how to read or write file metadata (such as file, group or channels properties) from an Analysis Automation Procedure script in DIAdem.

Analysis Automation Procedures can access files that match the search query using the DataLink Collection. Follow the relevant sections below to learn how to access properties in your data file from an Analysis Automation Procedure.
 

Opening the Main Script of the Analysis Automation Procedure


1. In DIAdem, select the SCRIPT Panel.
2. From the top menu bar, select Settings >> SystemLink TDM >> Analysis Automation Procedure.

Analysis Automation Procedure Menu.PNG

3. In the pop-up window, open an existing Analysis Automation Procedure (.ANP file). 4. Select the Analysis Script tab and double-click the Main script (.vbsa file if programming with Visual Basic Script, or .py file if programming with Python).

Analysis Script tab.PNG

 

Writing a Visual Basic Script (VBS) to Access Properties


After opening the .vbsa file in DIAdem, follow the steps below:
 
1. Scroll until you find the end Sub line of the On_Run_AnalysisProcedure(oContext) sub procedure.
  • Note: pay attention to the lines that define the DataLink variable. Once a file has been loaded using Navigator.LoadData(DataLink), it's properties can be accessed as usual.
2. Just before the end Sub line, add the following code to read/write properties:
  • To read file properties use Data.Root.Properties(<property name>).Value. For example:
'-- Access the file name
Dim sourcefilename
sourcefilename = Data.Root.Properties("name").Value
  • To write file properties use Data.Root.Properties(<property name>).Value = <value to set>. For example:
'-- Set the value of the Author property
Dim author
author = "NI"
Data.Root.Properties("author").Value = author
  • To read group properties use Data.Root.ChannelGroups(<group index or name>).Properties(<property name>).Value. For example:
'-- Read the Name property for Group 1
Dim groupname
groupname = Data.Root.ChannelGroups(1).Properties("name").Value
  • To write group properties use Data.Root.ChannelGroups(<group index or name>).Properties(<property name>).Value = <value to set>. For example:
'-- Set the Author property for Group 1
Dim author
author = "NI"
Data.Root.ChannelGroups(1).Properties("author").Value = author
  • To read channel properties use Data.Root.ChannelGroups(<group index or name>).Channels(<channel index or name>).Properties(<property name>).Value. For example:
'-- Read the Name property for Group 1 Channel 1
Dim channelname
channelname = Data.Root.ChannelGroups(1).Channels(1).Properties("name").Value
  • To write channel properties use Data.Root.ChannelGroups(<group index or name>).Channels(<channel index or name>).Properties(<property name>).Value = <value to set>. For example:
'-- Write the Description property for Group 1 Channel 1
Dim description
description = "This is an example description."
Data.Root.ChannelGroups(1).Channels(1).Properties("description").Value = description
 

Writing a Python Script to Access Properties


After opening the .py file in DIAdem, follow the steps below:

1. Scroll until you find the On_Run_AnalysisProcedure(oContext) function definition.
  • Note: pay attention to the lines that define the link variable. Once a file has been loaded using elements = dd.Navigator.LoadData(link), it's properties can be accessed as usual.
2. At the end of the function (below the oContext.LogResult("On_Run_AnalysisProcedure: End of Analysis procedure") line), add the following code to read/write properties:
  • To read file properties use dd.Data.Root.Properties("name").Value. For example:
# -- Read the Name property of the file
sourcefilename = dd.Data.Root.Properties("name").Value
  • To write file properties use dd.Data.Root.Properties(<property name>).Value = <value to set>. For example:
# -- Write the Author property of the file
author = "NI Engineer"
dd.Data.Root.Properties("author").Value = author
  • To read group properties use dd.Data.Root.ChannelGroups(<group index>).Properties(<property name>).Value. For example:
#-- read the Name property for Group 1
groupname = dd.Data.Root.ChannelGroups(1).Properties("name").Value
  • To write group properties use dd.Data.Root.ChannelGroups(<group index>).Properties(<property name>).Value = <value to set>. For example:
#-- Set the Description property for Group 1
groupdescription = "This is a test description"
dd.Data.Root.ChannelGroups(1).Properties("description").Value = groupdescription
  • To read channel properties use dd.Data.Root.ChannelGroups(<group index>).Channels(<channel index or name>).Properties(<property name>).Value. For example:
# -- read the Name property for Group 1 Channel 1
channelname = dd.Data.Root.ChannelGroups(1).Channels(1).Properties("name").Value
  • To write channel properties use dd.Data.Root.ChannelGroups(<group index>).Channels(<channel index or name>).Properties(<property name>).Value = <value to set>. For example:
#-- Set the Description property for Group 1 Channel 1
channeldescription = "This is a test description."
dd.Data.Root.ChannelGroups(1).Channels(1).Properties("description").Value = channeldescription