Question-and-Answer Resource for the Building Energy Modeling Community
Get s tarted with the Help page

The following excerpt from a measure.rb file is to get all surface of a "plenum" space that are of type "Floor" and have a "Surface" outside boundary condition. The lines "puts plenumSurface.name.get.to_s" and "puts plenumSurface.handle" show the results expected from reviewing the SketchUp/OpenStudio file and from reviewing the .OSM file. (I could then also use "plenumSurface.setConstruction(construction)" to assign construction to each of these surfaces, though I have not shown that below.)

However, I will also have to assign this construction to the adjacent surfaces for each of the above plenumSurface. So, I thought, I'd just use plenumSurface.adjacentSurface instead of plenumSurface to accomplish that. However, it seems that plenumSurface.adjacentSurface is a totally different class than plenumSurface. For example, ".name.get.to_s" and ".handle" work on plenumSurface, but not on plenumSurface.adjacentSurface. What gives?

plenumSurfaces = plenum.surfaces
plenumSurfaces.each do |plenumSurface|
if plenumSurface.surfaceType == "Floor" and plenumSurface.outsideBoundaryCondition == "Surface"
puts plenumSurface.name.get.to_s
puts plenumSurface.handle
puts plenumSurface.adjacentSurface.get.to_s # DOES NOT WORK!
puts plenumSurface.adjacentSurface.handle # DOES NOT WORK!
end
end


Thanks for any assistance you might be able to provide.

edit retag close merge delete

Sort by » oldest newest most voted

puts plenumSurface.adjacentSurface.get.to_s # DOES NOT WORK!

will return a string of the whole OS:Surface object. To get the name of the adjacent surface:

puts plenumSurface.adjacentSurface.get.name.to_s


As for

puts plenumSurface.adjacentSurface.handle # DOES NOT WORK!


you need to .get the adjacentSurface, otherwise you're asking for the handle of an OS:OptionalSurface, which is an undefined method for that class. Instead:

puts plenumSurface.adjacentSurface.get.handle


will return the adjacent surface's handle.

Note that all of the above will only work if the plenumSurface always has an adjacent surface defined, which might not always be the case. For more about making sure optional types exist before 'getting' them, see the bit about boost::optional in the measure writing guide.

more

Thank you kindly, Eric. So, it looks like the following does the job. (The "puts" lines are just for informational output. The real work gets done by the "setConstruction" lines, of course.

plenumSurfaces = plenum.surfaces
plenumSurfaces.each do |plenumSurface|
if plenumSurface.surfaceType == "Floor" and plenumSurface.outsideBoundaryCondition == "Surface"
puts plenumSurface
puts plenumSurface.name.to_s
puts plenumSurface.handle
plenumSurface.setConstruction(construction)

end
end


I agree about checking for adjacent surfaces, but in my (limited) case, I know I have those. Cool - another problem solved!

more