This repository demonstrates how to connect a VIKTOR app with STAAD.Pro by using the VIKTOR Python worker. The sample app creates a steel frame in STAAD.Pro, adds a self-weight load case, runs the analysis, and returns member end forces to the VIKTOR interface.
The worker script uses Bentley's official openstaadpy package for STAAD.Pro 2025 and newer. For older STAAD.Pro versions, use the legacy OpenSTAAD COM approach with pywin32 and comtypes.
app.py: VIKTOR app code. It sendsinputs.jsonto the Python worker throughviktor.external.python.PythonAnalysisand reads backoutput.json.run_staad_model.py: Python worker script that opens or connects to STAAD.Pro, creates the model through OpenSTAAD, runs the analysis, and writesoutput.json.worker-requirements.txt: Python packages to install in the Python environment used by the VIKTOR worker.viktor.config.toml: VIKTOR app configuration with the Python worker integration enabled.
Install the app requirements:
pip install -r requirements.txtThe Python worker must run on the same machine or server where STAAD.Pro is installed and licensed.
For STAAD.Pro 2025 and newer, install the worker dependencies in the Python environment selected during the Python worker installation:
pip install -r worker-requirements.txtThe official package is installed from Bentley's GitHub repository:
pip install git+https://github.com/BentleySystems/openstaadpy.gitFor STAAD.Pro versions older than 2025, use the legacy OpenSTAAD COM approach instead:
pip install pywin32 comtypesThis sample uses the VIKTOR Python worker and PythonAnalysis:
from viktor.external.python import PythonAnalysisThe app sends the worker script and an input file to the worker:
input_json = json.dumps([nodes, lines, cross_section])
script_path = Path(__file__).parent / "run_staad_model.py"
script = File.from_path(script_path)
files = [
("inputs.json", BytesIO(input_json.encode("utf-8"))),
]
staad_analysis = PythonAnalysis(
script=script,
files=files,
output_filenames=["output.json"],
)
staad_analysis.execute(timeout=300)
output_file = staad_analysis.get_output_file("output.json")
output = json.loads(output_file.getvalue().decode("utf-8"))To make the Python worker integration available in the VIKTOR interface, viktor.config.toml includes:
worker_integrations = [
"python",
]Manual Python worker installation instructions are available in the VIKTOR documentation.
run_staad_model.py first tries to connect to an already running STAAD.Pro instance. If no running instance is available, it tries to launch STAAD.Pro from common installation paths for STAAD.Pro 2025 and newer.
If STAAD.Pro is installed in a custom location, set the STAAD_PRO_EXECUTABLE environment variable on the worker machine:
$env:STAAD_PRO_EXECUTABLE = "C:\Program Files\Bentley\Engineering\STAAD.Pro 2025\STAAD\Bentley.Staad.exe"openstaadpyrequires STAAD.Pro to be installed and an OpenSTAAD-enabled STAAD.Pro instance to be available.- STAAD.Pro 2025 and newer should use
openstaadpy. - Older STAAD.Pro versions should use direct OpenSTAAD COM automation through
pywin32andcomtypes. - Keep the worker Python environment separate from the VIKTOR app environment. STAAD.Pro dependencies only need to be installed on the worker machine.
