Overwriting constructions in database

The VE Python API allows users create simple programs using the Python Programming Language, to interact with a VE Model and/or Vista Results File
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Overwriting constructions in database

Post by Tian »

Hi guys,
I am really looking forward to your help. My idea is to do a parametric study of changing building parameters. Therefore applying code may quickly change all the parameters in the same time. I have four questions according to constructions, thermal template and VEBody:

1. How to overwrite roof, wall and floor constructions in API.
I checked both manual and script examples and it seems that the methods defined there were only about window constructions.

2. How to set properties in each layer in the window when out pane and inner pane are different materials.
The script example assumes that the outpane and inner pane have the same properties so they loop each material and set the same material properties.
When I print(layers), It shows this:
[<iesve.VECdbLayer object at 0x0F3873F0>, <iesve.VECdbLayer object at 0x0F3871B0>, <iesve.VECdbLayer object at 0x0F3875F0>]
I was wondering is it possible to store them into list and then extract each of them so it is able to set different properties to outer pane and inner pane.

3. How to alter internal gains and air exchange for each specific existing template.
I have looked viewtopic.php?f=271&t=66455&sid=cd21900 ... f7e29bef63. Refer to the answer by the staff, it may have properties of add or remove internal gains and air exchange in API. I would like to know specific examples if it is possible.
I also doubted that if the way below is a good way to select the specific template to change.

Code: Select all

for template in templates_iter:
        if template.name=="Template1":
            room_settings = {'sat_perc_lower': 0.0,
                     'heating_setpoint': 19.0,
                     'cooling_setpoint': 21.0,
                     'dhw_units': 'l/h',
                     'cooling_setpoint_profile': '0',
                     'dhw_profile': '-', 
4. How to assign different constructions to different lists of rooms.
I was trying the way below to assign and when I printed surfaces, it seems it did not work.

Code: Select all

for body in bodies:
    if body.id==['SP000000']:
        surfaces=body.get_surfaces()
        print(surfaces)
However, my aim was to change visible transmittace, reflectance, g_value and u_value of window constructions for parametric studies.
I assume another way is to assign the construction in the user interface first and then modify existing window construction each time. Nevertheless, I found it is difficult to define these properties that the g-value and u-value was calculated instead of inputting, so we need to change emissivity, conductivity etc.

Therefore, my idea changed to that I build different constructions in the database and in each study I select one of them and assign to the rooms I want. I do not know which way is more making sense, or there is another way around this.

Thanks so much for your time and help, really appreciate it!
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Overwriting constructions in database

Post by Rhind »

Hi,

Let's see if I can help with your questions:

1. How to overwrite roof, wall and floor constructions in API.
Not sure which specific examples you're referring to, but usually where you see iesve.construction_class.glazed you can use a different value of iesve.construction_class for different construction types. So for roof, wall, floor etc you probably want iesve.construction_class.opaque.

Here are the possible values (taken from the manual):
none, opaque, glazed, hard_landscaping, soft_landscaping, shade, misc
2. How to set properties in each layer in the window when out pane and inner pane are different materials.
The 'layers' here is already a list, so you can access the individual layers in the usual way. layers[0] for the first layer, layers[1] for the second and so on.

3. How to alter internal gains and air exchange for each specific existing template.
Here's an example for adding to existing templates:

Code: Select all

""""
This example adds an air exchange and a casual gain to a thermal template
"""

import iesve   # the VE api

# Get the current VE project.  
project = iesve.VEProject.get_current_project()

# Get a list of known air exchange objects from the project:
air_exchanges = project.air_exchanges()

# Get a list of casual gain objects from the project:
casual_gains = project.casual_gains()

# Get a list of the known thermal templates
# Pass True to only get templates in use (assigned), False to get all templates
templates = project.thermal_templates(False)
    
# Loop through the templates
for template in templates.values():
    # Add the first gain and air exchange found to the template
    template.add_gain(casual_gains[0])
    template.add_air_exchange(air_exchanges[0])

    template.apply_changes()
    
print("Done!")
Your selection method will work as long as there are no templates that share a name. I would make sure all templates have unique names if you want to take that approach.

4. How to assign different constructions to different lists of rooms.
I'm not entirely clear on what you're asking here but you should be able to call assign_construction() on a VEBody. You need to specify a construction and a surface.

Hope that helps.
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Re: Overwriting constructions in database

Post by Tian »

Hi Rhind,
Thanks so much for your help! It helps me a lot!
According to the last question, what I mean was for example, I have 10 rooms in the model, and each 2 rooms have different window construction. How can I group bodies into different groups wisely so I am able to apply different constructions. Do I manually input room id to determine?

However, after practice of overwriting constructions, I have problems of
1.For the wall construction, the thickness of the material is not overwriting the database, while other keys like specific heat capacity etc can be overwritten.
2. For the window construction. the conductivity of pane is not overwriting the database, also when getting material from layers, the cavity returns none. Does it mean that the type of gas is not changeable from API. Since it influences a lot the u-value.It would be nice to alter it as well. If this is not doable, then I prefer to add new constructions in databases and assign them to different rooms.

In addition, I am wondering how can I install openpyxl in the python inside VE. I used xlsxwritter but this is limited. I would like to write to the existing excel. So openpyxl will be the choice and this one is not in the lib/site-packages.

Thanks so much for your time and help!!!
Best
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Overwriting constructions in database

Post by Rhind »

You can add bodies to lists and loop through them to repeat some action (e.g. assign) if that's what you mean? And yes the body ID is what uniquely identifies a body.

For opaque constructions like walls the thickness needs to be set at the layer level rather than the material one. Similarly you can't set conductivity for a non-opaque construction.

It is intended that a future version of the API will allow you to add your own cavity layers that you determine the properties of.

To help you add additional libraries, you can extend the python search path. In the VEScript Python Editor, click the configure button and add paths in the section at the bottom.
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Re: Overwriting constructions in database

Post by Tian »

Hi Rhind,
Thanks so much for your reply. Yes, I know how to assign different constructions to different bodies now. Then I will create new different window constructions into the database if this is the case. Anyway, good to know!

According to what you mentioned here.
Rhind wrote: Tue Mar 12, 2019 12:48 pm To help you add additional libraries, you can extend the python search path. In the VEScript Python Editor, click the configure button and add paths in the section at the bottom.
I actually tried this way, for example, if I want to add openpyxl package (which is not existing in the site-packages), I put the path of this folder under configuration path. But it still has errors importing openpyxl. Do I need to put openpyxl in a specific location or I need to install it in a way first? There is a setup.py in the folder and do not really know how to install it.
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Overwriting constructions in database

Post by Rhind »

I don't know how that package works but you might have to perform some setup or installation before you use it. Sometimes that involves running something from the command line using a Python interpreter or other tool, e.g. "Python setup.py install".
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Re: Overwriting constructions in database

Post by Tian »

Dear Rhind,

Thanks so much for your help. I have two more questions here and hope you could help me a bit.

1. I am wondering if it is possible to change outside_surface_emissivity and insider_surface_emissivity in the material level instead of construction level. Since the inside_surface_emissivity in outer pane and outside_surface_emissvity in inner pane are significant for the u-value and g-value of the window. However, according to the manual, These two properties are not included in the possible dictionaries. Therefore, I am wondering if there is a way to go around this?

2. I looked at at the sample of assign_to_bodies, and the code below didnt work well, it didnt successfully assign the construction.

Code: Select all

for surface in surfaces:
            # Only proceed to assign a construction if it's external glazing
            if surface.type == iesve.VESurface_type.ext_glazing:                     
                # Get the first glazing construction we can find
                construction = project.get_construction(ids[0], c_class)
                # Assign the glazing construction to the external glazing         
                body.assign_construction(construction, surface)
I printed suface.type and there is no surface type as ext_glazing, so I assumed this is the reason why the construction was not assigned. So I am wondering is there a way to solve this?

Thanks a lot for your time and help
Best
Tian
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Re: Overwriting constructions in database

Post by Tian »

Dear Rhind,
I got one more question about overwriting construction in API. I think maybe there is something wrong behind the set_properties.

I set_properties through script and then I runned the simulation from user interface, however, the properties turned to be the previous one, which might mean that set_properties didnt successfully saved into the database somehow. Or maybe it should have a command of apply_changes()(just like the thermal template does). Could you please have a look of this. Thanks so much for your time and help.

Best
User avatar
Rhind
IES Staff
IES Staff
Posts: 87
Joined: Fri Mar 22, 2013 5:06 pm

Re: Overwriting constructions in database

Post by Rhind »

Hi,

There is a known issue with set_properties() in CDB not retaining set values properly in the current version of the VE. This will be fixed in the next release.

In regards to the two queries:

1. If you call get_properties() on a non-opaque CDB material you should get 'inside_emissivity' and 'outside_emissivity' in the dictionary you get back.

2. In that sample no constructions will be assigned if there are no surfaces in the model of type ext_glazing. You could change the type check to another type or remove the if statement completely to get it to work with your model.

Hope that helps.
Tian
VE Newbie
VE Newbie
Posts: 8
Joined: Wed Feb 27, 2019 8:49 am

Re: Overwriting constructions in database

Post by Tian »

Thanks so much for your reply.

However, for the emissivity, you can only change it in the level of construction according to the manual, and also I tried to set them in the material level which was actually failed.

And for the second query, could you please tell me how you change the type of surface? when I read the surfaces in the model, it only had the type of ceiling, floor and wall.

Thanks a lot for your time and help
Post Reply