4

OpenStudio SDK model.runPeriod within interactive ruby console

Dear all,

I am quite confused how to use the OpenStudio SDK within the irb console. I have successfully run the code written by mdahlhausen in his answer here

In the command line when I call the model's run period, I am now getting:

image description

However whenever I try one of the methods listed under RunPeriod class seen here

such as

image description

Ruby tells me that the method is undefined. What I am I missing here?

Furthermore how can I display all the methods in the runPeriod class within the irb console? .methods called on the runPeriod class return what seems to be very generic methods see:

image description

While all the methods listed within the OpenStudio SDK are returned on the model class

Any insights would be most appreciated!

antonszilasi's avatar
1.5k
antonszilasi
asked 2016-12-28 14:39:32 -0500, updated 2017-01-03 10:10:15 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

4

model.runPeriod returns an optional type. To get the actual RunPeriod object you first need to check if the object is 'empty' (see the 'OpenStudio Measures and the boost::optional Type' section here). So for instance:

run = model.runPeriod.get if not model.runPeriod.empty?

will return an object of class OpenStudio::Model::RunPeriod if the osm has a run period object, or false if it doesn't.

Once you get the actual object, running the methods method will show the full list of methods for that object.

ericringold's avatar
10.6k
ericringold
answered 2016-12-29 10:09:08 -0500, updated 2016-12-29 10:12:18 -0500
edit flag offensive 0 remove flag delete link

Comments

This is by far the most annoying part of the OpenStudio SDK. Necessary perhaps, but ultra-annoying.

__AmirRoth__'s avatar __AmirRoth__ (2016-12-29 10:28:41 -0500) edit
2

I nominate this as most annoying, but fortunately it is pretty rare :). This is one of a few objects that take an optional double for set methods. So you have to make an optional double from a double to set a value.

@antonszilasi good question, but you may want to rename it to be more specific about the error you were seeing.

David Goldwasser's avatar David Goldwasser (2016-12-29 11:24:14 -0500) edit
add a comment see more comments