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

adjacent surface

asked 2017-05-03 18:24:14 -0500

Matt Koch gravatar image

updated 2017-05-03 19:06:41 -0500

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-05-03 19:27:17 -0500

updated 2017-05-04 09:33:04 -0500

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.

edit flag offensive delete link more
1

answered 2017-05-04 07:26:21 -0500

Matt Koch gravatar image

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)

    puts plenumSurface.adjacentSurface.get
    puts plenumSurface.adjacentSurface.get.name.to_s
    puts plenumSurface.adjacentSurface.get.handle
    plenumSurface.adjacentSurface.get.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!

edit flag offensive delete link more

Your Answer

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

Add Answer

 

Question Tools

1 follower

Stats

Asked: 2017-05-03 18:24:14 -0500

Seen: 162 times

Last updated: May 04 '17