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

Revision history [back]

click to hide/show revision 1
initial version

OpenStudio 3.2.1 - trouble with object creation in measure

I am writing a measure to mass-assign materials to constructions and constructions to default construction sets. The following bit of code produces a new DefaultSurfaceConstructions with option = true, but not with option = false.

if option then
  exterior_surface_constructions = OpenStudio::Model::DefaultSurfaceConstructions.new(model)
  exterior_surface_constructions = exterior_surface_constructions.setName(exterior_surface_constructions_name)

  surface_constructions = model.getDefaultSurfaceConstructionss()
  surface_constructions.each do |surface_construction|
    runner.registerInfo("Default Surface Construction = #{surface_construction.name()}")
  end

  exterior_surface_constructions = surface_constructions[-1]
end

if not option then
  exterior_surface_constructions = model.getDefaultSurfaceConstructionsByName(exterior_surface_constructions_name)

  runner.registerInfo("ESC after ByName: #{exterior_surface_constructions}")

  if exterior_surface_constructions.is_initialized then
    exterior_surface_constructions = exterior_surface_constructions.get
    runner.registerInfo("ESC after Get: #{exterior_surface_constructions}")
  else
    exterior_surface_constructions = OpenStudio::Model::DefaultSurfaceConstructions.new(model)
    exterior_surface_constructions = exterior_surface_constructions.setName(exterior_surface_constructions_name)
    runner.registerInfo("ESC after new and name: #{exterior_surface_constructions}")
  end
end

I find that I am having to take a similar detour to generate a new DefaultConstructionSet, also. It seems that the option = false approach would be the more correct one as it first checks if the object already exists, and it works with other objects in OpenStudio 3.2.1, but not with these two?