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

Revision history [back]

Feel free to adapt the following code, it'll give you some training on measures too!

# Find the north walls, with a big tolerance here.
between_deg = -25
until_deg = 25

# Conversions to SI units
between_rad = OpenStudio::convert(between_deg,"deg","rad").get
until_rad = OpenStudio::convert(until_deg,"deg","rad").get


# Construction: adapt to grep the construction you actually need
construction = model.getConstructionByName("North Construction").get

model.getSurfaces.each do |surface|
  # Find exterior walls only
  next if surface.outsideBoundaryCondition != "Outdoors"
  next if surface.surfaceType != "Wall"


  # Filter on azimuth: OpenStudio works CLOCKWISE (different from classic trigonometry), and returns it in radians
  # Also doesn't take care of the Building North Axis, it'll be in your original drawing (that's usually easier anyways)
  # If you want the north wall: 0, east: Pi/2, south: Pi , west: 3*Pi/2

  # Filter on azimuth
  azimuth = surface.azimuth
  # Case where start point was negative
  if between_rad > until_rad
      next if (azimuth > until_rad) && (azimuth < between_rad)
  else
      next if (azimuth < between_rad) || (azimuth > until_rad)
  end

  #surface.setConstruction(construction)
  puts "Assigned construction to #{surface.name} which has an azimuth of #{OpenStudio::convert(azimuth,"rad","deg").get} degrees"
end

Feel free to adapt the following code, it'll give you some training on measures too!too! I'd personally not create an actual measure for this, I'd just open a terminal window and do some interactive ruby on my model, but that's just me.

# Find the north walls, with a big tolerance here.
between_deg = -25
until_deg = 25

# Conversions to SI units
between_rad = OpenStudio::convert(between_deg,"deg","rad").get
until_rad = OpenStudio::convert(until_deg,"deg","rad").get


# Construction: adapt to grep the construction you actually need
construction = model.getConstructionByName("North Construction").get

model.getSurfaces.each do |surface|
  # Find exterior walls only
  next if surface.outsideBoundaryCondition != "Outdoors"
  next if surface.surfaceType != "Wall"


  # Filter on azimuth: OpenStudio works CLOCKWISE (different from classic trigonometry), and returns it in radians
  # Also doesn't take care of the Building North Axis, it'll be in your original drawing (that's usually easier anyways)
  # If you want the north wall: 0, east: Pi/2, south: Pi , west: 3*Pi/2

  # Filter on azimuth
  azimuth = surface.azimuth
  # Case where start point was negative
  if between_rad > until_rad
      next if (azimuth > until_rad) && (azimuth < between_rad)
  else
      next if (azimuth < between_rad) || (azimuth > until_rad)
  end

  #surface.setConstruction(construction)
  puts "Assigned construction to #{surface.name} which has an azimuth of #{OpenStudio::convert(azimuth,"rad","deg").get} degrees"
end

Feel free to adapt the following code, it'll give you some training on measures too! I'd personally not create an actual measure for this, I'd just open a terminal window and do some interactive ruby on my model, but that's just me.

# Find the north walls, with a big tolerance here.
between_deg = -25
until_deg = 25

# Conversions to SI units
between_rad = OpenStudio::convert(between_deg,"deg","rad").get
until_rad = OpenStudio::convert(until_deg,"deg","rad").get


# Construction: adapt to grep the construction you actually need
construction = model.getConstructionByName("North Construction").get

model.getSurfaces.each do |surface|
  # Find exterior walls only
  next if surface.outsideBoundaryCondition != "Outdoors"
  next if surface.surfaceType != "Wall"


  # Filter on azimuth: OpenStudio works CLOCKWISE (different from classic trigonometry), and returns it in radians
  # Also doesn't take care of the Building North Axis, it'll be in your original drawing (that's usually easier anyways)
  # If you want the north wall: 0, east: Pi/2, south: Pi , west: 3*Pi/2

  # Filter on azimuth
  azimuth = surface.azimuth
  # Case where start point was negative
  if between_rad > until_rad
      next if (azimuth > until_rad) && (azimuth < between_rad)
  else
      next if (azimuth < between_rad) || (azimuth > until_rad)
  end

  #surface.setConstruction(construction)
surface.setConstruction(construction)
  puts "Assigned construction to #{surface.name} which has an azimuth of #{OpenStudio::convert(azimuth,"rad","deg").get} degrees"
end

Feel free to adapt the following code, it'll give you some training on measures too! I'd personally not create an actual measure for this, I'd just open a terminal window and do some interactive ruby on my model, but that's just me.

# Find the north walls, with a big tolerance here.
between_deg = -25
until_deg = 25

# Conversions to SI units
between_rad = OpenStudio::convert(between_deg,"deg","rad").get
until_rad = OpenStudio::convert(until_deg,"deg","rad").get


# Construction: adapt to grep the construction you actually need
construction = model.getConstructionByName("North Construction").get

model.getSurfaces.each do |surface|
  # Find exterior walls only
  next if surface.outsideBoundaryCondition != "Outdoors"
  next if surface.surfaceType != "Wall"


  # Filter on azimuth: OpenStudio works CLOCKWISE (different from classic trigonometry), and returns it in radians
  # Also doesn't take care of the Building North Axis, it'll be in your original drawing (that's usually easier anyways)
  # If you want the north wall: 0, east: Pi/2, south: Pi , west: 3*Pi/2

  # Filter on azimuth
  azimuth = surface.azimuth
  # Case where start point was negative
  if between_rad > until_rad
      next if (azimuth > until_rad) && (azimuth < between_rad)
  else
      next if (azimuth < between_rad) || (azimuth > until_rad)
  end

  # Assign the construction to the surface
  surface.setConstruction(construction)
  puts "Assigned construction to #{surface.name} which has an azimuth of #{OpenStudio::convert(azimuth,"rad","deg").get} degrees"
end

Feel free to adapt the following code, it'll give you some training on measures too! I'd personally not create an actual measure for this, I'd just open a terminal window and do some interactive ruby on my model, but that's just me.

# If interactive, load model
path = 'C:\mymodel.osm'
translator = OpenStudio::OSVersion::VersionTranslator.new
ospath = OpenStudio::Path.new(path)
model = translator.loadModel(ospath)
if model.empty?
    raise "Path #{path} is not a valid path to an OpenStudio Model"
else
    model = model.get
end    

# Find the north walls, with a big tolerance here.
between_deg = -25
until_deg = 25

# Conversions to SI units
between_rad = OpenStudio::convert(between_deg,"deg","rad").get
until_rad = OpenStudio::convert(until_deg,"deg","rad").get


# Construction: adapt to grep the construction you actually need
construction = model.getConstructionByName("North Construction").get

model.getSurfaces.each do |surface|
  # Find exterior walls only
  next if surface.outsideBoundaryCondition != "Outdoors"
  next if surface.surfaceType != "Wall"


  # Filter on azimuth: OpenStudio works CLOCKWISE (different from classic trigonometry), and returns it in radians
  # Also doesn't take care of the Building North Axis, it'll be in your original drawing (that's usually easier anyways)
  # If you want the north wall: 0, east: Pi/2, south: Pi , west: 3*Pi/2

  # Filter on azimuth
  azimuth = surface.azimuth
  # Case where start point was negative
  if between_rad > until_rad
      next if (azimuth > until_rad) && (azimuth < between_rad)
  else
      next if (azimuth < between_rad) || (azimuth > until_rad)
  end

  # Assign the construction to the surface
  surface.setConstruction(construction)
  puts "Assigned construction to #{surface.name} which has an azimuth of #{OpenStudio::convert(azimuth,"rad","deg").get} degrees"
end