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

Revision history [back]

The OpenStudio GUI supports only supports adding specific component types (Materials, Constructions, and Ductless Heat Pumps). This is done via the "Components and Measures / Find Components" menu item.

The API can access any kind of component on the BCL. This is demonstrated in the Get BCL Weather File user script in the sketchup plugin.

I have a few unpublished measures that exercise the api (One to get site components, another to get construction). I'll see if I can get one of these posted on BCL as en example The trick to using a measure that accesses BCL components is planning it in a way so that the search results that populate the choice list are not too long. The user script can iterate (e.g. first pick city, then pick from sub-set of weather files for that city). A measure has to do it in one pass.

The OpenStudio GUI supports only supports adding specific component types (Materials, Constructions, and Ductless Heat Pumps). This is done via the "Components and Measures / Find Components" menu item.

The API can access any kind of component on the BCL. This is demonstrated in the Get BCL Weather File user script in the sketchup plugin.

I have a few unpublished measures that exercise the api (One to get site components, another to get construction). I'll see if I can get one of these posted on BCL as en example The trick to using a measure that accesses BCL components is planning it in a way so that the search results that populate the choice list are not too long. The user script can iterate (e.g. first pick city, then pick from sub-set of weather files for that city). A measure has to do it in one pass.

Here is a short snippet if you already know the UID of the component you want.

remote = OpenStudio::RemoteBCL.new
remote.downloadComponent(uid)
component = remote.waitForComponentDownload()

if component.empty?
  runner.registerError("Cannot find local component")
  return false
end
component = component.get

# get osc file
files = component.files("osc")
if files.empty?
  runner.registerError("No file found")
  return false
end
construction_path = component.files("osc")[0]
construction_file = OpenStudio::IdfFile::load(construction_path)
vt = OpenStudio::OSVersion::VersionTranslator.new
constructionComponent = vt.loadComponent(OpenStudio::Path.new(construction_path))

if constructionComponent.empty?
  runner.registerError("translateSurfaceConstruction: Cannot load construction component '#{construction_file}'")
  return false
else
  object = constructionComponent.get.primaryObject
  if object.to_Construction.empty?
    runner.registerError("translateSurfaceConstruction: Construction component '#{construction_file}' does not include a construction object")
    return false
  else
    componentData = model.insertComponent(constructionComponent.get)
    if componentData.empty?
      runner.registerError("translateSurfaceConstruction: Failed to insert construction component '#{construction_file}' into model")
      return false
    else
      new_construction = componentData.get.primaryComponentObject.to_Construction.get
    end
  end
end

The OpenStudio GUI supports only supports adding specific component types (Materials, Constructions, and Ductless Heat Pumps). This is done via the "Components and Measures / Find Components" menu item.

The API can access any kind of component on the BCL. This is demonstrated in the Get BCL Weather File user script in the sketchup plugin.

I have a few unpublished measures that exercise the api (One to get site components, another to get construction). I'll see if I can get one of these posted on BCL as en example The trick to using a measure that accesses BCL components is planning it in a way so that the search results that populate the choice list are not too long. The user script can iterate (e.g. first pick city, then pick from sub-set of weather files for that city). A measure has to do it in one pass.

Here is a short snippet if you already know the UID of the component you want.

# get component
remote = OpenStudio::RemoteBCL.new
remote.downloadComponent(uid)
component = remote.waitForComponentDownload()
 if component.empty?
  runner.registerError("Cannot find local component")
  return false
end
component = component.get

# get osc file
files = component.files("osc")
if files.empty?
  runner.registerError("No file found")
  return false
end
construction_path = component.files("osc")[0]
construction_file = OpenStudio::IdfFile::load(construction_path)
vt = OpenStudio::OSVersion::VersionTranslator.new
constructionComponent = vt.loadComponent(OpenStudio::Path.new(construction_path))

# get model boject
if constructionComponent.empty?
  runner.registerError("translateSurfaceConstruction: Cannot load construction component '#{construction_file}'")
  return false
else
  object = constructionComponent.get.primaryObject
  if object.to_Construction.empty?
    runner.registerError("translateSurfaceConstruction: Construction component '#{construction_file}' does not include a construction object")
    return false
  else
    componentData = model.insertComponent(constructionComponent.get)
    if componentData.empty?
      runner.registerError("translateSurfaceConstruction: Failed to insert construction component '#{construction_file}' into model")
      return false
    else
      new_construction = componentData.get.primaryComponentObject.to_Construction.get
    end
  end
end

The OpenStudio GUI supports only supports adding specific component types (Materials, Constructions, and Ductless Heat Pumps). This is done via the "Components and Measures / Find Components" menu item.

The API can access any kind of component on the BCL. This is demonstrated in the Get BCL Weather File user script in the sketchup plugin.

I have a few unpublished measures that exercise the api (One to get site components, another to get construction). I'll see if I can get one of these posted on BCL as en example The trick to using a measure that accesses BCL components is planning it in a way so that the search results that populate the choice list are not too long. The user script can iterate (e.g. first pick city, then pick from sub-set of weather files for that city). A measure has to do it in one pass.

Here is a short snippet if you already know the UID of the component you want.

# get component
download from BCL
remote = OpenStudio::RemoteBCL.new
remote.downloadComponent(uid)
component = remote.waitForComponentDownload()
if component.empty?
  runner.registerError("Cannot find local component")
  return false
end
component = component.get

# get osc file
files = component.files("osc")
if files.empty?
  runner.registerError("No file found")
  return false
end
construction_path = component.files("osc")[0]
construction_file = OpenStudio::IdfFile::load(construction_path)
vt = OpenStudio::OSVersion::VersionTranslator.new
constructionComponent = vt.loadComponent(OpenStudio::Path.new(construction_path))

# get model boject
object
if constructionComponent.empty?
  runner.registerError("translateSurfaceConstruction: Cannot load construction component '#{construction_file}'")
  return false
else
  object = constructionComponent.get.primaryObject
  if object.to_Construction.empty?
    runner.registerError("translateSurfaceConstruction: Construction component '#{construction_file}' does not include a construction object")
    return false
  else
    componentData = model.insertComponent(constructionComponent.get)
    if componentData.empty?
      runner.registerError("translateSurfaceConstruction: Failed to insert construction component '#{construction_file}' into model")
      return false
    else
      new_construction = componentData.get.primaryComponentObject.to_Construction.get
    end
  end
end

The OpenStudio GUI supports only supports adding specific component types (Materials, Constructions, and Ductless Heat Pumps). This is done via the "Components and Measures / Find Components" menu item.

The API can access any kind of component on the BCL. This is demonstrated in the Get BCL Weather File user script in the sketchup plugin.

I have a few unpublished measures that exercise the api (One to get site components, another to get construction). I'll see if I can get one of these posted on BCL as en example The trick to using a measure that accesses BCL components is planning it in a way so that the search results that populate the choice list are not too long. The user script can iterate (e.g. first pick city, then pick from sub-set of weather files for that city). A measure has to do it in one pass.

Here is a short snippet if you already know the UID of the component you want.

# download from BCL
remote = OpenStudio::RemoteBCL.new
remote.downloadComponent(uid)
component = remote.waitForComponentDownload()
if component.empty?
  runner.registerError("Cannot find local component")
  return false
end
component = component.get

# get osc file
files = component.files("osc")
if files.empty?
  runner.registerError("No file found")
  return false
end
construction_path = component.files("osc")[0]
construction_file = OpenStudio::IdfFile::load(construction_path)
vt = OpenStudio::OSVersion::VersionTranslator.new
constructionComponent = vt.loadComponent(OpenStudio::Path.new(construction_path))

# get model object
if constructionComponent.empty?
  runner.registerError("translateSurfaceConstruction: Cannot load construction component '#{construction_file}'")
  return false
else
  object = constructionComponent.get.primaryObject
  if object.to_Construction.empty?
    runner.registerError("translateSurfaceConstruction: Construction component '#{construction_file}' does not include a construction object")
    return false
  else
    componentData = model.insertComponent(constructionComponent.get)
    if componentData.empty?
      runner.registerError("translateSurfaceConstruction: Failed to insert construction component '#{construction_file}' into model")
      return false
    else
      new_construction = componentData.get.primaryComponentObject.to_Construction.get
    end
  end
end

Here is the entire run section of a measure that creates model objects from all the OSC files from a "resources" directory within the measure.

# define what happens when the measure is run
def run(model, runner, user_arguments)
super(model, runner, user_arguments)

# use the built-in error checking
if !runner.validateUserArguments(arguments(model), user_arguments)
  return false
end

# report initial condition of model
runner.registerInitialCondition("The building started with #{model.numObjects} objects.")

# get all objects in directory
files = Dir.entries("#{File.dirname(__FILE__)}/resources/")
files.each do |new_object|
  next if not new_object.include?(".osc")
  runner.registerInfo("importing component from #{new_object}")

  #load the osc file
  new_object_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/resources/#{new_object}")
  new_object_file = OpenStudio::IdfFile::load(new_object_path)

  if new_object_file.empty?
    runner.registerError("Unable to find the file #{new_object}.osc")
    return false
  else
    new_object_file = new_object_file.get
  end

  vt = OpenStudio::OSVersion::VersionTranslator.new
  new_objectComponent = vt.loadComponent(OpenStudio::Path.new(new_object_path))
  if new_objectComponent.empty?
    runner.registerError("Cannot load new_object component '#{new_object_file}'")
    return false
  else
    object = new_objectComponent.get.primaryObject
    componentData = model.insertComponent(new_objectComponent.get)
    if componentData.empty?
      runner.registerError("Failed to insert new_object component '#{new_object_file}' into model")
      return false
    else
      new_new_object = componentData.get.primaryComponentObject
    end
  end

end

# report final condition of model
runner.registerFinalCondition("The building finished with #{model.numObjects} objects.")

return true

end