Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

How to add layer using command line measures?

asked 2019-03-27 03:53:30 -0500

Eyal zilber's avatar

updated 2019-03-27 11:02:39 -0500

Hello, I want to add a material layer to an existing construction using the command line interface. I didn't find any measure that allows it. Any recommendations?

edit retag flag offensive close merge delete


There are two ways to do this - make a measure that you run through command line, or write a ruby script to add it. Which do you prefer for your workflow?

mdahlhausen's avatar mdahlhausen  ( 2019-03-27 11:37:41 -0500 )edit

Some other information that would be useful to know, is if you are going to make a material for this layer on the fly or pick from materials already in the model. Also will you want to specify the position of this material relative to other layers.

David Goldwasser's avatar David Goldwasser  ( 2019-03-27 12:00:47 -0500 )edit

Thank you for the response. I want to add a new material layer in the external face i.e layer index =0, by using a ruby script.

Eyal zilber's avatar Eyal zilber  ( 2019-03-28 10:42:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-28 11:04:54 -0500

Here is some code borrowed from the Office and K12 AEDG envelope measures.

# make new material
exposedMaterialNew =

# set requested material properties
if !options['roughness'].nil? then exposedMaterialNew.setRoughness(options['roughness']) end
if !options['thickness'].nil? then exposedMaterialNew.setThickness(options['thickness']) end
if !options['conductivity'].nil? then exposedMaterialNew.setConductivity(options['conductivity']) end
if !options['density'].nil? then exposedMaterialNew.setDensity(options['density']) end
if !options['specificHeat'].nil? then exposedMaterialNew.setSpecificHeat(options['specificHeat']) end
if !options['thermalAbsorptance'].nil? then exposedMaterialNew.setThermalAbsorptance(options['thermalAbsorptance']) end
if !options['solarAbsorptance'].nil? then exposedMaterialNew.setSolarAbsorptance(options['solarAbsorptance']) end
if !options['visibleAbsorptance'].nil? then exposedMaterialNew.setVisibleAbsorptance(options['visibleAbsorptance']) end

# add material to construction
construction.insertLayer(options['layerIndex'], exposedMaterialNew)

In this example options is a hash that contains data about the new material as well as the target layer index. It is in a resource file in a method named addNewLayerToConstruction that takes a construction and the options hash.

edit flag offensive delete link more


I wrote the following code : require_relative 'os_lib_constructions' include OsLib_Constructions addNewLayerToConstruction_Inputs = { "roughness" => "MediumRough", "thickness" => 0.2, # meters, "conductivity" => 0.22, # W/m*K "density" => 650.0, "specificHeat" => 950.0, "thermalAbsorptance" => 0.9, "solarAbsorptance" => 0.7, "visibleAbsorptance" => 0.7, } newmaterial = OsLib_Constructions.addNewLayerToConstruction('Wall_N',addNewLayerToConstruction_Inputs) I receive the message "undefined method `model' for "Wall_N":String

Eyal zilber's avatar Eyal zilber  ( 2019-04-01 06:25:44 -0500 )edit

@Eyal zilber the first argument should be an OpenStudio Construction object not a name. So it could be something like model.getConstructions.first, or if you want to get a construction by name, then something like model.getConstructionByName('Wall_N").get.

Also the comments mid line when defining the hash for addNewLayerToConstruction_Inputs are also problematic. If want to document the units, do it at the end of the line or on a separate line.

David Goldwasser's avatar David Goldwasser  ( 2019-04-01 08:46:16 -0500 )edit

Still getting the error, I want to simplify the code by creating a material in the openstudio application and name it as: "Wall_Insulation". and then run the generate_workflow.rb file, with the addition of the code : construction = model.getConstructionByName("Wall_N") NewMaterial = model.getMaterialByName("Wall_Insulation") construction.insertLayer('0' , NewMaterial) when execute I receive an error: "undefined local variable or method `model' for main: Object". when using the previous code pointing to the OsLib_Constructions I receive the same error. appreciate your help

Eyal zilber's avatar Eyal zilber  ( 2019-04-01 10:03:56 -0500 )edit

Are you running this inside of a measure that already has access to model in the run method, or are you just writing a script to modify on a model on the fly. If that is the case, you will have to manually load the model. You can see how to do this by looking the ruby code in a measure test, search for # load the test model

What is generate_workflow.rb being used for? Just altering the model, or is it also running the simulation on the resulting model?

David Goldwasser's avatar David Goldwasser  ( 2019-04-01 12:28:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops


Question Tools

1 follower


Asked: 2019-03-27 03:53:30 -0500

Seen: 253 times

Last updated: Mar 28 '19