Running TRNSYS from Python

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.

  1. Generate VFM and SHM/ISM in TRNBuild
  2. exporting a Dck file in Simulation Studio
  3. 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.

# 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'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight\building_ModGeo.b18" /N /vfm')
    # Creating SHM/ISM from command line'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\ExamplesD_Building_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'"C:\TRNSYS18\Studio\Exe\Studio.exe" /d /q "C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight\Building.tpf"')

    # TRNSYS
    # Running TRNSYS in interactive mode'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck"', cwd=r'C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight')

    # Running TRNSYS in batch mode
    #'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /n', cwd=r'C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight')

    # Running TRNSYS in Hidden mode'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /h', cwd=r'C:\TRNSYS18\ExamplesD_Building_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)


Leave a Comment

Your email address will not be published. Required fields are marked *