9 Sep 2021

How to Script the Instantiation of a Python Script Object Xtra

This Xtra provides a script template that can be used to instantiate a Python script object Xtra from the Python console or from a Python script.


The first two lines are dedicated to retrieving the AMIRA_LOCAL (or AVIZO_LOCAL) variable, which can be useful depending on the installation procedure of the Xtra you chose (see the Help section on that topic).

### Declaration of variable AMIRA_LOCAL (or AVIZO_LOCAL) ###
import os
# Retrieve AMIRA_LOCAL path value.
amiraLocal = os.getenv('AMIRA_LOCAL')
### Instantiation of Xtra Python module ###
# Create the Python Script Object instance.
yourPythonModule = hx_project.create("HxPythonScriptObject")
yourPythonModule.name = "ModuleName"
# Set the path to the corresponding .pyscro file.
yourPythonModule.ports.filename.filenames = amiraLocal + "/share/python_script_objects/yourPythonScriptObject.pyscro"
# Load the .pyscro file.
yourPythonModule.ports.startStop.buttons[0].hit = 1
yourPythonModule.fire()
# Hide undesired ports.
yourPythonModule.ports.startStop.visible = 0
yourPythonModule.ports.filename.visible = 0