Running TRNSYS from Python
2018年2月27日
2023年5月4日
The Python subprocess module makes it easy to run external programs.
TRNBuild, Simulation Studio and TRNSYS can be run from the command line.
So, you can use Python to run a series of TRNSYS operations at once.
The following example shows how to run a multi-zone model in Python.
- Generate VFM and SHM/ISM in TRNBuild
- exporting a Dck file in Simulation Studio
- run TRNSYS.
This may not seem to be a popular use, but it may be useful in cases where the calculation is repeated over and over again.
RunTRNSYS.py
# coding: utf-8
"""
This example shows how to run TRNBuild, Simulation Studio and TRNSYS.
coded by Yuichi Yasuda @ quattro corporate design
"""
import subprocess
#from subprocess import Popen
if(__name__ == '__main__'):
# TRNBuild
#--------------------------------------------------------------------------------------------------------------------------------
# Creating VFM from command line
subprocess.call(r'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight\building_ModGeo.b18" /N /vfm')
# Creating SHM/ISM from command line
subprocess.call(r'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight\building_ModGeo.b18" /N /masks')
# Simulation Studio
#--------------------------------------------------------------------------------------------------------------------------------
# Creating DCK file from command line.
# command line options
# /d create deck file
# /r run simulation
# /q quit
subprocess.call(r'"C:\TRNSYS18\Studio\Exe\Studio.exe" /d /q "C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight\Building.tpf"')
# TRNSYS
#--------------------------------------------------------------------------------------------------------------------------------
# Running TRNSYS in interactive mode
#subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck"', cwd=r'C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight')
# Running TRNSYS in batch mode
# subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /n', cwd=r'C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight')
# Running TRNSYS in Hidden mode
subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /h', cwd=r'C:\TRNSYS18\Examples\3D_Building\6_Step_Add_Daylight')
Test Environment
It has been confirmed that the software works in the following environments.
Windows10 Pro(64bit)
Python:Anaconda 5.1(Python 3.6/64bit)
TRNSYS18.00.0017(64bit)