×
Menu
Index

4 Creating a Sample Script

A common task with VE Python scripting is to extract room level data results from an aps file. Many of the methods of the ‘ResultsReader’ class in the VE Python API, require ‘room_id’ to be passed in as an argument.
 
In most cases we would want to use room groups in the VE to specify which rooms we would like to include in our analysis. For example we might want to extract the room air temperatures from each space in our model in order to perform an overheating check. We would however, only be concerned with the temperature in certain space types i.e. ‘Offices’, ‘Meeting Rooms’, etc. We would want to exclude spaces types such as ‘Voids’ from our analysis. In this case we would use room groups to specify which room types we would like to be included in our analysis.
 
In this section we will walk-through the steps involved in creating a simple script, to interrogate the grouping schemes in our model. We will then use this to generate a list of all of the room ids in our model that’s exclude the rooms in the ‘Void’ group. Before we begin, we must manually create a grouping scheme in our model called ‘Thermal Template’. This grouping scheme contains the groups shown below.
 
 
Once we start a new script, the first task is to import the VE API into the project.
 
 
Create an instance of the RoomGroups interface object using ‘iesve.RoomGroups()’ and assign it to a variable. The variable can be named anything. In this example we will assign it to the variable named ‘rg’. The RoomGroups interface object will allow us to interact with the Grouping Schemes in the VE model.
 
 
 
 
We will now create a list of the grouping schemes contained in our model. Each individual grouping scheme will be represented as a Python Dictionary object. Each grouping scheme dictionary has the following entries:
 
Key
value type
handle
(int)
name
(string)
 
We will essentially be creating a list of dictionaries. To do this we will call the ‘get_grouping_schemes()’ method on the RoomGroups object. We will then assign the list of grouping schemes to another variable. In this example we will name this variable ‘schemes’.
 
 
Using a ‘for loop’ we will iterate through our list of grouping schemes and print the name of each grouping scheme to the console.
 
 
We will now create a list of the groups contained within each grouping scheme. Firstly we declare a new variable inside the loop and assign the scheme handle to it. We will call this variable ‘scheme_handle’. We then call the method ‘get_room_groups()’ on our RoomGroups interface object and pass in the scheme handle as an argument. We assign this list of groups to a new variable which we have called ‘groups’.
 
 
Again each individual group in the list is represented as a Python Dictionary object which contains data the about the group. Each grouping scheme dictionary has the following entries:
 
 
 
Key
value type
colour
(tuple of R,G,B ints)  each colour entry in range 0-255
handle
(int)
name
(string)
rooms
(list of strings) list of room IDs assigned to group
 
Finally we iterate though the list of groups using another for loop. We then print the name of each group and a list of the room ids for every room contained in each group.
 
 
We want to obtain a list of the room ids for all of the rooms in our model excluding the rooms in the ‘Void’ group. Firstly we declare a new variable before the first for loop. We call it ‘room_ids’ and assign it to an empty list. Next inside the second for loop we create an ‘If’ statement. The If statement below reads as follows: if the grouping scheme name is equal to ‘Thermal Template’ and the group is not equal to ‘Void’, then add the room ids for that group into the ‘room_ids’ list. This means that the rooms ids for all of the other groups will be added to the ‘room_ids’ list. Finally we print the ‘room_ids’ list to the console to manually verify that our script is working correctly.
 
 
We have now created a list of room ids which could be used for many different tasks within the VE Python API. VE Scripts >> api_examples contains many other example scripts to demonstrate other useful functions of the VE Python API.