DIAdem Help

General Information on Python Scripts

  • Updated2024-09-12
  • 4 minute(s) read

General Information on Python Scripts

In DIAdem you can execute Python scripts in the SCRIPT panel in addition to VBS scripts. You specify the script language in the DIAdem Settings for SCRIPT. DIAdem uses the selected script language when you capture scripts and when you create a new script. In the DIAdem settings for SCRIPT, you can also specify the program path of an installed Python version. If you do not specify a path or the path does not contain a Python version supported by DIAdem, DIAdem also looks for a valid Python installation in the paths of the Windows Path system variable. If DIAdem cannot find a valid Python installation, DIAdem uses the Python version of the DIAdem installation.

DIAdem does not support Python in user commands or in SUD dialog boxes. The Script Profiler does not support Python scripts.

Currently, DIAdem for Python does not support virtual environments with virtualenv or venv.

NI recommends not mixing VBS and Python scripts. To use Python syntax from program areas that do not support Python, you can use the ScriptStart command to start your Python scripts from VBS scripts.

The Python print() function generates an output in the Watch area of DIAdem SCRIPT. You can use these for debug output, for example.

Using DIAdem variables, enumerations, methods, and objects in Python requires importing the Application object of the DIAdem Python module. Therefore, DIAdem generates the required line of code when you create a new Python script. In addition, DIAdem generates lines of code that allow autocompletion while editing the Python script and when debugging with an external debugger:

Important Differences between VBS and Python Syntax in DIAdem

The script examples in the programming interface help are currently only available in VBS syntax. You can also use most of the examples in Python if you change them slightly and add the text “dd." before DIAdem commands, DIAdem variables, DIAdem objects, and DIAdem bullets. You also need to adapt the control structures and field access to the Python syntax.

For DIAdem commands and methods that do not require parameters, you can omit the parentheses after the call in VBS scripts, whereas you must always set the parentheses in Python scripts.

Global variables, to which a value in a DIAdem Python script is assigned, retain that value even after the script ends. A similar behavior occurs when importing Python modules with the import command. After you have imported a module, Python in DIAdem does not automatically detect when the module changes unless you reload it with importlib.reload, for example: import MySub; import importlib; importlib.reload(MySub).

In DIAdem, the transfer parameters of a method can also receive return values. This call is currently not supported in DIAdem Python scripts, so the following call will cause an error: dd.Portal.GetFloatingPos(dTop, dLeft)

The index of DIAdem arrays always starts with 1, the index of Python arrays always starts with 0. If you access DIAdem variables through Python, they are still 1-based, for example, dd.HICRes[1,1] returns the first data element of the result matrix of an HIC calculation.

If you access a collection with parentheses in the object-oriented interface, Python behaves like VBS. DIAdem automatically complements the Item method. In Python syntax you therefore also access the first worksheet in DIAdem REPORT, for example, with dd.Report.Sheets(1).

Many DIAdem commands contain optional parameters. In VBS scripts you can omit the optional parameters even if they are not the last parameters. In Python scripts you must specify a value for these parameters, for text parameters, for example, this is an empty string.

Debugging a Python Script

To debug Python scripts, you cannot use the internal debugger of DIAdem, but must use an external debugger instead. If you start Python scripts and have enabled external debugging, DIAdem does not execute the scripts until you have connected the external debugger.

Report Generation and Data Visualization with Python

Python programmers usually create reports and visualize their data using scripts. This is also possible in DIAdem. In DIAdem we recommend you define your scripts interactively. With DIAdem REPORT and DIAdem VIEW, you can interactively configure single- and multi-page reports or your data visualization template, and save them as TDR or TDV files. Then load these files into your Python script using the LoadLayout for Report and LoadLayout for View methods to display your data in reports or visualize your data.

The page Notes on Python contains further general information about Python.

You can find more documentation about Python at https://www.python.org/.

Python examples

AC/DC Coupling | Analysis of Two Electric-Powered Race Cars | Area Calculation between Curves | ASCII File Loading and 3D Display | Automatically Creating a PowerPoint Presentation | Calculate Characteristics of an Oscillation | Calculating and Checking a Corridor | Calculating Process Capability | Calculating the Gear Transmission Ratio | Calculating the GPS Track | Calculating with Waveform Channels | Color Marker Depending on Channel | Combining DataFinder Search Results | Comparing Speed | Connect and Mirror Channels | Convert Polar Coordinates to Cartesian Coordinates | Converting Units | Copying Signals into Channel Groups | Crash Analysis | Creating a Python DataPlugin | Creating an Excel File | Creating and Viewing Long Data Channels | Detrending an Oscillation Signal | Error Bar Display | Error Handling in Scripts | Evaluating a Shock Response Spectrum | Event Search | Find Pattern in Signals | Flow Cytometry | Frequency Weighting (A-, B-, C-Filtering) | Mapping a Channel onto an Integer Data Type | Merging Channels from Different Measurements | Multiple Sorting of Channel Data | Non-Linear Curve Fitting | Pareto Diagram | Printing Reports Automatically as PDF | Removing Repeatedly Occurring Values in a Channel | Resampling | Savitzky-Golay Filter | Searching for and Interpolating Invalid Values | Searching for Data Sets Marked "Failed" in Data Stores | Searching for Data Sets Marked "Failed" | Searching for Events in Channels | Searching for Outliers with the ChnEvent Function | Searching for Outliers with the Peak Search Function | Seismic Phase Picker | Smoothing Signals with the 4253H Filter | Smoothing Signals | Sorting Channel Groups | Sorting the Channels in the Default-Group | Specifying Intersection Points | Swivel Analysis at the Engine | Synchronizing Measurement Data | Table with Automatic Row Height | Test Rig Analysis | Viewing and Automatically Analyzing Data