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

Revision history [back]

click to hide/show revision 1
initial version

Big thanks to all the folks who helped here (@macumber and @david-goldwasser).

I pushed out a solution on github here

My solution proved very similar to David's final proposal. I'm not sure it's the most elegant or "Ruby" way of doing this, but I created a class which was Comparable (I called it SpaceSort). The whole purpose of this class was to sort an array of OpenStudio::Model::Spaces by their bounding box limits. The order of heirarchy:

  • min_x > max_x >min_y > max_y >min_z > max_z

The code here might explain it better.

I then use that class to sort my spaces so that they are always consistent.

def sort_spaces(spaces)

# Array of SpaceSort objects, used to sort spaces by their bounding boxes
space_sort_list = []

# Construct SurfaceSort objects for sorting surfaces
spaces.each do |space|
    space_sort_list << SpaceSort.new(space)
end

# sort SurfaceSort objects by their bounding box boundaries
sorted_list = space_sort_list.sort()

sorted_spaces = []

# Extract spaces from sorted SurfaceSort objects
sorted_list.each do |space_sort|
    sorted_spaces << space_sort.space
end

return(sorted_spaces)

end

Once sorted, this behavior became consistent and, at least in this model, fixed my issue. I'll have to do more extensive testing to make sure this is a generalized solution to this problem.