Query the number of model stories using OpenStudio sdk

I am wondering if it is possible to get the number of stories in a model using the OpenStudio SDK, I thought that I could do this using the standardsNumberOfStories property in the Building class reference.

2 Answers

building.standardsNumberOfStories just access a field to store optional metadata. It doesn't actually inspect other model elements. There are other options. You could simply do model.getBuildingStorys.size to count story objects, but that may also count building story objects that are not assigned to any spaces. Some other issues are dealing with zone multiplier and plenums/attics. In the openstudio-standards gem there is a model_effective_num_stories method. This addresses many of these issues, and others such as identifying below vs. above grade stories. I believe it does expect spaces to already be assigned to building story objects. If you are working with a generic model that may not have story objects you can use the AssignSpacesToStories measure on BCL which evaluates the z value of floors in spaces, creates a story object for common values, and assign the spaces to the new story.

When an optional value is returned, it may or may not have a value inside it. You need to use special code to retrieve its value if one exists. See the "OpenStudio Measures and the boost::optional Type" section of the Measure Writer's Guide for a good explanation of how to handle this.

In your specific case, the returned value is optional because OpenStudio models can be created that do not have the number of stories specified.