How to trigger a Python script from a menu item using an SVB wrapper macro in Spotfire Statistica ?

book

Article ID: KB0138471

calendar_today

Updated On:

Products Versions
Spotfire Statistica 14.0.1 and above

Description

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.

Environment

Windows operating system

Resolution

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).

    image.png

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).

    image.png

Step 3: Add the Macro to your Menu

  • Right-click on the Use classic menus tab and select Customize Quick Access Toolbar...
    image.png

  • In the Categories list on the left side, select Macros.

    image.png

  • You will see your TriggerPython macro appear below the Macro category; add it to your toolbar.

    image.png

    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:

  1. IronPython Workspace (statpy.sdm): This workspace is configured specifically for IronPython. Please note that IronPython is deprecated and is no longer supported. For more information, please refer to the Spotfire Statistica 14.2.0 Release Notes.
  2. Python 3.14 Workspace (statpy_Python314.sdm): This workspace is configured to run with Python 3.14. Users are highly encouraged to use this version for future compatibility.

Issue/Introduction

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. 

Attachments

statpy with Python 314.sdm get_app
SVB Code.docx get_app
statpy.sdm get_app