20. Scripting#

Scripting console window showing Python command interface

NaxToView contains an embedded Python console that allows users to execute Python commands, launch Python scripts, and execute application functions.

NaxToView includes functions designed to be executed from the scripting console.

20.1. Basic Usage#

Most actions performed in NaxToView produce the equivalent command in the scripting console.

Example: To select elements in the model:

  1. Set Item to Elements

  2. Hold Shift + right-click and drag to select elements

Scripting console showing auto-generated selection command

The command Session.Windows[0].Views[0].Scene.SelectionPicking.SelectGlobalIds(<…>) appears in the console. If you clear the selection and execute that command, the same elements will be selected.

Clear button in the scripting console toolbar

The Clear button clears the scripting console output.

This is useful for automating tasks. More complex tasks can be executed using File → Run Python Script.

File menu showing Run Python Script option

Note

If the selected elements do not appear highlighted in the viewport, the viewport has not refreshed after the scripting command. Click anywhere in the 3D viewport to force a refresh.

20.2. Application Overview#

Understanding the application hierarchy is essential for using scripting methods as intuitively as the GUI.

The scripting console provides access to two scopes:

  • Command: Provides built-in methods for executing scripts. For example:

Command scope example in the scripting console
  • Session: Contains all the information and methods accessible to users

The architecture overview is as follows:

Application hierarchy diagram showing Session, Windows, Views, and Scene structure

20.3. Detailed Functionality#

Loading a New Model#

Case 1: Load from a new session (i.e., NaxToView has just started)

NaxToView creates a new Window, View, and Scene to store the model. If a scene with a model already exists, the new model replaces it.

Case 2: A session with an existing model is already open. Load a model in a specific view.

  1. Create a new view in the first window:

    Session.Windows[0].CreateView("New view")
    
  2. Load a model in the newly created view:

    Session.Windows[0].Views[1].LoadModel1FEM(r"C:\Models\wind3.op2")
    

Selection of Elements and Nodes#

Entities can be selected in two ways:

  1. Global IDs (used internally by the rendering engine)

  2. Solver IDs — always composed of a superelement (or part) and an element/node ID

ID encoding: NaxToView encodes ID ranges as strings for ease of use. The string begins with control characters:

  • 'E' or 'N' — indicating whether elements or nodes are being selected

  • ':' and 'S' — for solver selection

The string begins with '#Part_<part id>@' followed by the compressed ID string. Each range is defined with :, and each group is split with ,.

Example: IDs 1, 2, 3, 6, 7, 8 would be encoded as "1:3,6:8"

The following example selects elements 34750 to 34760, and 34800 to 34806:

Session.Windows[0].Views[0].Scene.SelectionPicking.SelectGlobalIds("E:S#Part_0@34750:34760,34800:34806")

Creation of Macros#

Users can create custom macros in NaxToView. Macros execute scripts directly from the application interface.

Tools menu showing Macros submenu with user-defined macros

Macros can be created in two ways:

Option 1: Create from the User Interface#

  1. Click Tools → Macros → Create Macro

  2. In the dialog, define:

    • The macro name

    • The script to execute (either a new script or an existing script file)

    • Whether it should be available for all users

  3. Click OK

  4. The Scripting IDE opens with the script selected for the macro

Option 2: Create via Scripting#

  1. Place the script file in the macros folder:

    • User-specific: %LOCALAPPDATA%\IDAERO\NaxTo_<version>\macros

    • System-wide: C:\ProgramData\IDAERO\NaxTo_<version>\macros

  2. Create the macro from the scripting console:

    # User-only macro
    Session.CreateMacro("First macro", "Test.py")
    
    # System-wide macro (available to all users)
    Session.CreateMacro("First macro", "Test.py", system_macro=True)
    

This stores the new macro in macro_dict.xml so it is available on the next application launch.

Note

Script files must have the .py extension and unique names. If a macro with the same name already exists, the creation will fail.

Managing Macros#

Once created, the macro appears in the Tools → Macros menu.

Right-click the macro to delete it or open the Scripting IDE to edit it. Deleting a macro removes it from macro_dict.xml, but the associated script file remains in the macros folder.

Alternatively, manage macros via the scripting API:

Session.EditMacro("NameOfMacro")
Session.DeleteMacro("NameOfMacro")
Session.RenameMacro("NameOfMacro", "NewName")

To move a macro between the AppData and ProgramData folders:

  1. Delete the macro using Session.DeleteMacro("NameOfMacro")

  2. Move the script file to the target folder

  3. Recreate the macro with system_macro=True if moving to ProgramData

Creation of Buttons#

Users can add custom buttons to the interface.

To create a button:

  1. Place the script file in the actions folder:

    • User-specific: %LOCALAPPDATA%\IDAERO\NaxTo_<version>\actions

    • System-wide: C:\ProgramData\IDAERO\NaxTo_<version>\actions

  2. (Optional) Add a .png icon file to the icons folder inside the actions directory (create the icons folder if it does not exist)

  3. Create the button from the scripting console:

    # User button
    Session.CreateButton("NewButton", "Test.py", "Test.png")
    
    # System button (available to all users)
    Session.CreateButton("NewButton", "Test.py", "Test.png", system_button=True)
    

Note

  • The button name must be a single word. CamelCase and underscores are allowed

  • The button name must be unique

  • The script file must have the .py extension and a unique name

  • If the icon parameter is omitted, the button name is displayed instead

This stores the new button in action_dict.xml so it is available on the next application launch.

Reposition the button by dragging it via the dotted vertical separator on its left edge.

Delete a button with:

Session.DeleteButton("ButtonName")

This removes the button from action_dict.xml but leaves the associated script in the actions folder.

To rename a button, delete it and recreate it with the new name.

Loading Scripts on Startup#

You can define actions to execute on application startup.

Add the commands to the autorun.py script in the actions directory:

  • User-specific: %LOCALAPPDATA%\IDAERO\NaxTo_<version>\actions

  • System-wide: C:\ProgramData\IDAERO\NaxTo_<version>\actions

To execute a specific script on load, add the following to autorun.py:

Command.ExecuteScript(r"C:\path\to\script.py")

20.4. Scripting IDE#

The Scripting IDE allows you to create and run Python scripts within NaxToView. Scripts can range from simple command sequences to complex automation workflows with custom interfaces and buttons.

Opening the Scripting IDE#

The IDE can be opened in three ways:

1. Via the View menu:

Click View → Scripting IDE

View menu showing Scripting IDE option

2. When creating a macro:

Click Tools → Macros → Create Macro

Tools menu showing Macros submenu with Create Macro option

3. From the scripting console:

Right-click in the scripting console and select Open Scripting IDE

Right-click context menu in the scripting console

The Scripting IDE opens with the session script already loaded:

Scripting IDE window with the current session script loaded

20.4.1. IDE Controls#

The IDE provides the following controls:

Scripting IDE toolbar showing all control buttons

Icon

Control

Description

New

Opens a new blank file and closes the currently open file

Open

Opens an existing file

Save

Saves the file

Refresh

Refreshes the file contents if the file has been modified by another program

Edit

Cut, Copy, and Paste

Font Settings

Adjusts font size and style

Indent

Indent right or left

Run Script

Runs the script in the current session

20.4.2. Autocomplete#

The IDE includes autocomplete for all methods and attributes available in Session and its child objects.

Autocomplete icon indicating a method

Method

Autocomplete icon indicating an attribute

Attribute

Autocomplete dropdown showing available methods and properties

Pressing . displays a dropdown with the available methods and properties. In this example, the methods and properties are related to a Window.

Hover over a method or property name to view its documentation.

Autocomplete tooltip showing method documentation

20.5. Execution of NaxToView Via Command Line#

NaxToView can be launched from the command line with optional parameters.

20.5.1. Basic Execution#

Navigate to the folder containing the NaxToView executable:

C:\Program Files\IDAERO\NaxTo\NaxTo_202xRx\NAXTOVIEW\bin

Run the following command:

NaxToView.exe
Command line showing the NaxToView executable path

The result of running the executable:

NaxToView launching from the command line

20.5.2. Command-Line Parameters#

NaxToView supports the following command-line parameters. These parameters enable advanced functionality: launching with a custom interface mode, executing a script on startup, or running in the background without displaying the UI.

Parameter

Description

Example

--help

Display the help screen

NaxToView.exe --help

--version

Display version information

NaxToView.exe --version

--mode <mode>

Specifies the interface to open. Accepted values: excel, powerpoint, word

NaxToView.exe --mode excel

--script <path>

Specifies the script to be executed when the application starts. Provide the full path to the script file

NaxToView.exe --script "C:\Scripts\test.py"

--visualization <true|false>

Controls whether NaxToView displays its interface. Default: true. Use false to run the application in the background

NaxToView.exe --visualization false --script "C:\Scripts\batch.py"

Warning

To use --mode, the target application (Excel, Word, or PowerPoint) must already be running. If it is not open, NaxToView will fail to start.

Examples#

Opening NaxToView in Excel mode:

NaxToView launched with --mode excel, embedded in Excel interface

Opening NaxToView in Word mode:

NaxToView launched with --mode word, embedded in Word interface

Opening NaxToView in PowerPoint mode:

NaxToView launched with --mode powerpoint, embedded in PowerPoint interface

Running a script on startup:

Command line example using the --script parameter

Running without visualization:

Command line example using the --visualization false parameter

Tip

Parameters can be combined in a single command. For example, use --visualization false and --script together to run a script silently in the background. NaxToView closes automatically when the script finishes.