Has anyone else been playing with the Python scripting interface in version 2017?
I have managed to get a grip with the absolute basics but there are a few things which are eluding me.
1) Has anyone found the "variables list" which details what room level variables can be interrogated through the API and what they are called? It is referenced throughout the VE Python Script User Guide but I cannot find the list itself. This means, for example, that I cannot figure out how to interrogate the room air temperatures from my Vista file.
2) Is it possible to interrogate .htg and .clg results files? I can only find mention of .aps files in the current guide and I would like to set up a script to work with CIBSE heating and cooling loads. The IESFilePicker utility only allows .aps files to be selected by the user.
Thanks
CP
VEScript - Python Questions
- Complex Potential
- VE Expert

- Posts: 467
- Joined: Wed Jan 09, 2013 11:57 am
- Location: Bristol, UK
Re: VEScript - Python Questions
The easiest place to get the list of variables for a results file is by using the get_variables API on the file itself. Note that some files can have different variables, in particular apm files.
The variables list returned by get_variables has 1 dictionary per variable. The dictionary shows the (internal) aps variable name, the display name (what you'd see in Vista/VistaPro), the model level flag, and the units type for that variable.
You can use the units type together with the units data returned by get_units() to do unit conversion or display the units along with a value.
With regards to your second question, yes clg/htg files are also supported. There is a more generic vista file picker available for that purpose.
Here is a sample script showing both the generic results file picker and the output of get_variables():
The variables list returned by get_variables has 1 dictionary per variable. The dictionary shows the (internal) aps variable name, the display name (what you'd see in Vista/VistaPro), the model level flag, and the units type for that variable.
You can use the units type together with the units data returned by get_units() to do unit conversion or display the units along with a value.
With regards to your second question, yes clg/htg files are also supported. There is a more generic vista file picker available for that purpose.
Here is a sample script showing both the generic results file picker and the output of get_variables():
Code: Select all
import iesve # the VE api
import pprint
from ies_file_picker import IesFilePicker
pp = pprint.PrettyPrinter()
# Open results file (multiple types):
file_name = IesFilePicker.pick_vista_file([("APS files", "*.aps"), ("HTG files", "*.htg"), ("CLG files", "*.clg")], "Pick a results file")
with iesve.ResultsReader.open(file_name) as results_file_reader:
assert results_file_reader is not None, "Error opening results file"
# get the variables and units for this file
aps_variables = results_file_reader.get_variables()
aps_units = results_file_reader.get_units()
print("Nr of variables: {}".format(len(aps_variables)))
print("Nr of units: {}".format(len(aps_units)))
pp.pprint(aps_variables)
- Complex Potential
- VE Expert

- Posts: 467
- Joined: Wed Jan 09, 2013 11:57 am
- Location: Bristol, UK
Re: VEScript - Python Questions
Thanks MacdewMacdew wrote:The easiest place to get the list of variables for a results file is by using the get_variables API on the file itself. Note that some files can have different variables, in particular apm files.
The variables list returned by get_variables has 1 dictionary per variable. The dictionary shows the (internal) aps variable name, the display name (what you'd see in Vista/VistaPro), the model level flag, and the units type for that variable.
You can use the units type together with the units data returned by get_units() to do unit conversion or display the units along with a value.
With regards to your second question, yes clg/htg files are also supported. There is a more generic vista file picker available for that purpose.
Here is a sample script showing both the generic results file picker and the output of get_variables():
Code: Select all
import iesve # the VE api import pprint from ies_file_picker import IesFilePicker pp = pprint.PrettyPrinter() # Open results file (multiple types): file_name = IesFilePicker.pick_vista_file([("APS files", "*.aps"), ("HTG files", "*.htg"), ("CLG files", "*.clg")], "Pick a results file") with iesve.ResultsReader.open(file_name) as results_file_reader: assert results_file_reader is not None, "Error opening results file" # get the variables and units for this file aps_variables = results_file_reader.get_variables() aps_units = results_file_reader.get_units() print("Nr of variables: {}".format(len(aps_variables))) print("Nr of units: {}".format(len(aps_units))) pp.pprint(aps_variables)
I've gotten to grips with the results file variables but I'm now really struggling with getting model input data using the get_internal_gains() command.
I have the following imports:
Code: Select all
import iesve
import xlsxwriter
import xlrd
from win32com.client import Dispatch
from ies_file_picker_rcm import IesFilePicker # handy little file picker utility for samples
import ctypes # An included library with Python install.
from os import walk
import getpass
Code: Select all
cas_gains = room_data.get_internal_gains()
for cas_gain in cas_gains:
gains_data = cas_gain.get()
print(gains_data)
Then I tried this:
Code: Select all
for body in bodies:
room_data = body.get_room_data(0)
cas_gains = room_data.get_internal_gains()
for cas_gain in cas_gains:
gains_data = cas_gain.get()
print(gains_data)

But I’ve not had much luck filtering them.
I tried using the isinstance function next but it did not recognise any internal gains of the type mentioned.
Code: Select all
for body in bodies:
room_data = body.get_room_data(0)
cas_gains = room_data.get_internal_gains()
for cas_gain in cas_gains:
gains_data = cas_gain.get()
if isinstance(gains_data, iesve.RoomLightingGain):
print("Found a lighting gain")
elif isinstance(gains_data, iesve.RoomPeopleGain):
print("Found a people gain")
elif isinstance(gains_data, iesve.RoomPowerGain):
print("Found a power gain")
else:
print("Error: unknown internal gain type")
I could really be doing with seeing a basic example of how to print a lighting gain for a specific room within a model. Once I've got that I think I'll be able to do the rest.
Any and all advice gratefully welcomed!
Thanks
CP
Re: VEScript - Python Questions
Hi,
Your script just needs a little tweak to get it to work.
If you change 'gains_data = cas_gain.get()' to simply 'gains_data = cas_gain' it should give you what you want.
Get() gives you the value of the object rather the object itself, so 'isinstance' always fails to report a match.
Hope that helps
Your script just needs a little tweak to get it to work.
If you change 'gains_data = cas_gain.get()' to simply 'gains_data = cas_gain' it should give you what you want.
Get() gives you the value of the object rather the object itself, so 'isinstance' always fails to report a match.
Hope that helps
Re: VEScript - Python Questions
Hi CP,
As mentioned by Rhind, the get() call returns the data for an internal gain - which is of type dict. For the isinstance compare, you need to compare the internal gain object itself (cas_gain in your script).
Here is a little sample that writes out the lighting gains for all currently selected rooms:
As mentioned by Rhind, the get() call returns the data for an internal gain - which is of type dict. For the isinstance compare, you need to compare the internal gain object itself (cas_gain in your script).
Here is a little sample that writes out the lighting gains for all currently selected rooms:
Code: Select all
import iesve # the VE api
project = iesve.VEProject.get_current_project()
real_building = project.models[0]
# get all the bodies in the building
bodies = real_building.get_bodies(False)
for body in bodies:
# skip any bodies that aren't thermal rooms
if body.type != iesve.VEBody_type.room:
continue
# do a test to see if we want this room...
# for instance, this only passes selected rooms
if not body.selected:
continue
num_gains_printed = 0
room_data = body.get_room_data(0)
cas_gains = room_data.get_internal_gains()
for cas_gain in cas_gains:
if not isinstance(cas_gain, iesve.RoomLightingGain):
continue
# passed all the checks, get the actual gains data
# and print it out
gains_data = cas_gain.get()
print(gains_data)
num_gains_printed += 1
if num_gains_printed == 0:
print("No lighting gains found for room: " + body.id)
- Complex Potential
- VE Expert

- Posts: 467
- Joined: Wed Jan 09, 2013 11:57 am
- Location: Bristol, UK
Re: VEScript - Python Questions
Thank you both very much for taking the time to help out this python rookie.
My script is now working although I doubt it's particularly elegant. I'm finding the IES specific methods and functions the most difficult thing to get to grips with. They all seem to work slightly differently and I'm trying to keep up with all the class hierarchies, lists, dictionaries, tuples and the methods and syntax for each.
I'm slowly getting there I think....
My script is now working although I doubt it's particularly elegant. I'm finding the IES specific methods and functions the most difficult thing to get to grips with. They all seem to work slightly differently and I'm trying to keep up with all the class hierarchies, lists, dictionaries, tuples and the methods and syntax for each.
I'm slowly getting there I think....
