| Products | Versions |
|---|---|
| Spotfire Statistica | 14.0.1 and above |
This article explains a method for executing Python (.py) scripts from Statistica menu items by utilizing a Statistica Visual Basic (SVB) wrapper macro to trigger an embedded Python workspace.
Windows operating system
To successfully configure and trigger a Python script via a menu item, follow these steps:
Step 1: Set up the Workspace
In Statistica, create a new Workspace and add a Python Node.
Paste your desired Python script into that node.
Save the Workspace to a folder on your machine (for example, C:\Statistica_py\statpy.sdm).
Step 2: Configure the TriggerPython SVB Macro
Open a new SVB script in Statistica.
Write a script to open the workspace in the background, execute it, and close it.
Ensure you update the file path in the macro script to match exactly where you saved your Workspace in Step 1 (e.g., workspacePath = "C:\Statistica_py\statpy.sdm").
Go to File > Save As and save this script as a Global Macro (*.svb).

Step 3: Add the Macro to your Menu
Right-click on the Use classic menus tab and select Customize Quick Access Toolbar...
In the Categories list on the left side, select Macros.
You will see your TriggerPython macro appear below the Macro category; add it to your toolbar.
Note: Deploying and maintaining customized menu structures through direct StatOpts.xml modifications is considered an advanced product customization and falls outside the scope of standard product support.
Step 4: Ensure Output Visibility
Because this SVB setup runs the workspace silently in the background, any spreadsheets or reports your Python script generates will not automatically pop up on the screen.
To make them visible to the user, you must explicitly set the visibility property to True inside the Python code.
For a spreadsheet: Add s.Visible = True to your object.
For a report: Add r.Visible = True to your object.
Important Note: Attached Workspaces & Deprecation
There are two workspace files attached to this article to accommodate different Python environments:
While Statistica menu items are natively designed to trigger .svb macros, users can seamlessly run Python code from these menus using an SVB macro as a bridge. This article outlines how to create an SVB macro that silently triggers a Statistica workspace containing a Python node, allowing for full integration of Python scripts into existing menu-driven workflows.
Feedback submitted!