1

adjacent surface

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.

Matt Koch's avatar
2k
Matt Koch
asked 2017-05-03 18:24:14 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2017-05-03 19:06:41 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

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!

Matt Koch's avatar
2k
Matt Koch
answered 2017-05-04 07:26:21 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
1

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.

ericringold's avatar
10.6k
ericringold
answered 2017-05-03 19:27:17 -0500, updated 2017-05-04 09:33:04 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments