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

How to get all OS objects and their members?

asked 2021-06-18 01:19:17 -0600

xchen's avatar

updated 2021-07-09 17:46:46 -0600

Is there a way to get all the os objects and the public member function in some format of data structure? For example, based on the class reference here, https://openstudio-sdk-documentation....








edit retag flag offensive close merge delete


You could use your preferred programming language to scrape the OpenStudio SDK website and compile the list of classes/methods.

shorowit's avatar shorowit  ( 2021-06-18 10:50:32 -0600 )edit

This is a good suggestion I'll try that.

xchen's avatar xchen  ( 2021-06-20 20:43:56 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2021-06-18 07:32:31 -0600

updated 2021-06-24 16:26:56 -0600

Rereading your question, you seem specifically interested in getting/generating a single structure/file with all OpenStudio nested classes/methods. I'm not sure if that exists in one file. Following a somewhat similar approach to what's described below, you could script your way to a solution by instantiating single instances of each upper class object, and recursively looping through each object method/member; then go through derived classes; and so on; e.g.

point3D =, 0, 0)
puts point3D.public_methods(false)

or simply

puts OpenStudio::Point3d.instance_methods(false)

Some effort (!), but manageable.

--- original answer ---

By getting, I assume you mean via the OpenStudio API (e.g., a Ruby script). A bare-bones example of one way to do it (first make sure you can access the OpenStudio Ruby gem):

require "openstudio"

# Load in memory OpenStudio Model (a "warehouse" example):
translator =
file = "warehouse.osm"
path = + file)
model = translator.loadModel(path)
raise "Invalid OSM" if model.empty?
model = os_model.get

At this point, you should have access to a valid OSM, which you can probe with the API. You'll find many examples here at UnmetHours like this.

air_loops = model.getAirLoopHVACs
plant_loops = model.getPlantLoops
zones = model.getThermalZones

Note the pattern between the get prefix and the class name e.g. getThermalZones. You can then retrieve objects attributes e.g.

zones.each do |zone|
  puts zone.nameString 
  puts zone.multiplier

Loops are neat/safe - the object may be empty (i.e. no zones in the OSM). Otherwise, one needs to pay attention to optional attributes (such as ThermalZone volume, which may not be initialized). Again, lots of examples on how to do this at UnmetHours, within OpenStudio Measures, etc.

You can also retrieve all model objects at once, then try to convert them into specific objects like the ones above.

edit flag offensive delete link more


This makes sense. I think I'll try a hybrid approach of what you described and what shorowit suggested above.

xchen's avatar xchen  ( 2021-06-20 20:45:52 -0600 )edit

I tried use .instance_methods(false) and noticed that what I got did not 100% match what's on the SDK website. For example, I applied it for ThermalZone, and instance_methods did not return addEquipment, which is listed here (https://openstudio-sdk-documentation....). Is there a reason for that?

xchen's avatar xchen  ( 2021-06-24 00:40:46 -0600 )edit

Can you try:

puts OpenStudio::Model::ThermalZone.instance_methods(false).grep(/equipment/i)

or if you first instantiated a thermal "zone" object:

puts zone.public_methods(false).grep(/equipment/i)

... both should return a (long) list of methods that contain the regex "equipment", including addEquipment. You can narrow down the search by replacing "/equipment/i" with "/addEquipment/"

Denis Bourgeois's avatar Denis Bourgeois  ( 2021-06-24 07:36:20 -0600 )edit

I tried and it returned a list of methods that contain "equipment", including "removeEquipment", but not "addEquipment". I double checked I'm using openstudio application v1.1.0 with core 3.1.0, and the SDK document I use if 3.1.0. I tried to use thermalZone.addEquipment and got error "undefined method". Anyways I'm just wondering why these two don't match and which one is right as I'm trying to get all methods for a certain class. Sounds like they should match right?

xchen's avatar xchen  ( 2021-06-24 12:27:14 -0600 )edit

Huh! I am indeed able to reproduce your exact observations with API/SDK v3.2 (my previous response was based on v2.9.1). addEquipment remains a listed ThermalZone method in the online v3.2 SDK, yet if I:


... on a newly instantiated ThermalZone object, I get the same NoMethodError (undefined method). Sounds like the online SDK needs updating (?).

Denis Bourgeois's avatar Denis Bourgeois  ( 2021-06-24 16:10:12 -0600 )edit

answered 2021-06-21 12:37:14 -0600

updated 2021-06-21 12:51:30 -0600

This function will get all the "setters" for a specific class, e.g. BuildingStory, without the need for instantiation. The same can be done for getters, resetters, autosizers, etc. and could be adapted to simply get all the instance_methods as @Denis Bourgeois suggested.

# return an array of all set methods for specific class_name string
def get_setters(class_name)

  array = []

  instance_methods = OpenStudio::Model.const_get(class_name).instance_methods
  instance_methods.each do |instance_method|
    array << instance_method if instance_method.to_s.start_with? 'set'
  array.pop(12) # remove the last 12 elements, which are general setters

  return array

edit flag offensive delete link more


Besides the getter and setters, is there a way to get the constructor for an object? For example, what's in the bracket: ExteriorLights (const ExteriorLightsDefinition &definition, bool useControlOptionAstronomicalClock=false), and ExteriorLights (const ExteriorLightsDefinition &definition, Schedule &schedule), so that I know what I need to provide when creating a new object (without looking at the SDK document)?

xchen's avatar xchen  ( 2021-08-27 21:32:35 -0600 )edit

Actually I was able to get it from the .hpp files.

xchen's avatar xchen  ( 2021-08-28 00:42:06 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Question Tools



Asked: 2021-06-18 01:19:17 -0600

Seen: 212 times

Last updated: Jun 24 '21