How to create a Measmatic export filter#
What is an export filter#
An export filter in Measmatic is a special Python script that processes data acquired during test execution. Through the flexibility of it's nature as Python script, an export filter is able to transform and store this measurement data according to any specification. This could be a custom file like Excel or CSV. It could also be rendered as an image or transmitted to a database.
Export filter skeleton#
A good start for creating an export filter is either to copy an existing one and make adjustments or to start from scratch with the help of this script:
#
# Measmatic export filter
#
# Unique identifier for the export filter
Guid = "e2295c20-f027-4cd0-bbc5-8e6ba9182a65"
# Optional caption which will be used in Measmatic UI
# If no caption is set, the name of the python file will be used as caption
Caption = "Custom file export (*.txt)"
# Optional description for the export filter
Description = "Describes what the export filter does."
# Options to configure the export. Those options will be displayed in Measmatic
# when this export filter is chosen
Settings = [
{
'type' : 'directory',
'settings' : {
'default' : 'C:\Measmatic\ExportData',
}
},
{
'type' : 'file_name',
'settings' : {
'default' : '<TESTNAME>.txt',
}
},
]
# this is the export function called by Measmatic
def ExportData(data_export):
pass
The script goes into the directory ExportFilter
which can be found inside the Measmatic data directory defined during setup. Default is C:\Measmstic
.
To enable debugging like shown on page Debugging python tests the file name for the export filter must not contain any spaces.
Inside the python script an object of type DataExport is passed as parameter data_export
to the function ExportData
. This object enables access to all data need during export.
Export filter variables#
In the export filter several variables are defined which are evaluated when Measmatic loads the export filter. Those variables provide the information necessary to work with the export filter in Measmatic and configure it properly.
Guid
#
Every export filter in Measmatic has its own unique identifier. This is done through this variable. A GUID for a new filter could be generated for example on https://www.guidgen.com/.
Caption
#
The caption is an optional value which defines the name which is used in Measmatic for the export filter. If no caption is provided, the file name will be used instead.
Description
#
The description provides additional information on the export filter for Measmatic users. It is displayed on the export filter configuration page. Defining this variable is optional.
Settings
#
This Variable can be used to define settings for the export filter, which later can be set in the configuration of this export filter within Measmatic. Within the export filter script the value can be retrieved with the method DataExport.GetSetting(settingId: string).
The following settings are available:
directory
#
This is used to set a target directory for the file the export filter writes. It corresponds to the method DataExport.GetFilePath() which is used while running the export filter. This could look like this:
def ExportData(data_export):
for test in data_export.Tests:
file_path = data_export.GetFilePath(test)
The special thing is that the user might define placeholders within the path which later are replaced by Measmatic when the method is called. For example the placeholder <TESTNAME>
would be replaced by the actual test name. All available placeholders are presented in Measmatic in the export filter settings if the directory
setting is used. The setting is intended to be used together with the setting file_name
.
The directory setting is defined as follows:
{
'type' : 'directory',
'settings' : {
'default' : 'C:\Measmatic\ExportData',
}
}
The ID for getting the value via DataExport.GetSetting(settingId: string) of this setting is always directory
.
file_name
#
This is used to set a name for the file the export filter writes. It corresponds to the method DataExport.GetFilePath() which is used while running the export filter. This could look like this:
def ExportData(data_export):
for test in data_export.Tests:
file_path = data_export.GetFilePath(test)
The special thing is that the user might define placeholders within the path which later are replaced by Measmatic when the method is called. For example the placeholder <TESTNAME>
would be replaced by the actual test name. All available placeholders are presented in Measmatic in the export filter settings if the file_name
setting is used. The setting is intended to be used together with the setting directory
.
The directory setting is defined as follows:
{
'type' : 'file_name',
'settings' : {
'default' : '<TESTNAME>.txt',
}
}
The ID for getting the value via DataExport.GetSetting(settingId: string) of this setting is always file_name
.
boolean
#
Defines a boolean setting which is presented as a checkbox in the Measmatic UI. It will return True
if the box checked, otherwise false
. It is defined like this:
{
'type' : 'boolean',
'settings' : {
'id' : 'boolean_setting_id',
'caption' : 'Caption for boolean setting',
'default' : False,
}
}
id
enables to retrieve the setting's value during export filter script execution like this:
def ExportData(data_export):
boolean_value = data_export.GetSetting('boolean_setting_id')
The value of caption
is used as label for this setting in Measmatic and the default
's value is used as initial value when this export filter is selected as data export in a Measmatic test or project.
integer
#
Defines an integer setting which is presented as a textbox in the Measmatic UI. It is defined like this:
{
'type' : 'integer',
'settings' : {
'id' : 'integer_setting_id',
'caption' : 'Caption for integer setting',
'default' : 42,
}
}
id
enables to retrieve the setting's value during export filter script execution like this:
def ExportData(data_export):
integer_value = data_export.GetSetting('integer_setting_id')
The value of caption
is used as label for this setting in Measmatic and the default
's value is used as initial value when this export filter is selected as data export in a Measmatic test or project.
string
#
Defines a string setting which is presented as a textbox in the Measmatic UI. It is defined like this:
{
'type' : 'string',
'settings' : {
'id' : 'string_setting_id',
'caption' : 'Caption for string setting',
'default' : 'default string',
}
}
id
enables to retrieve the setting's value during export filter script execution like this:
def ExportData(data_export):
string_value = data_export.GetSetting('string_setting_id')
The value of caption
is used as label for this setting in Measmatic and the default
's value is used as initial value when this export filter is selected as data export in a Measmatic test or project.