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

How to delete ModelObject in OpenStudio with Ruby bindings?

asked 2017-01-12 10:08:53 -0500

dalin_si's avatar

updated 2017-01-12 10:48:18 -0500

I'm confused in recent how a object in openstudio to be deleted or removed? for some object such as AirLoopHVAC, it has method .remove, but for some components, such as coil, unit heater, PTAC, they don't have method to delete from model.

Using unit heater as example, I can remove it from thermal zone, remove the components in this unit heater (fan, coil, etc.) but how can I remove it completely from model, get rid off it from the list which called from model.getZoneHVACUnitHeaters ?

is there have a general method to delete or remove modelobject completely from model? I can't not find it in ModelObject Class Reference or its child hierarchy.

Sorry to ask fundamental ruby questions all the time.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-01-12 13:50:19 -0500

updated 2017-01-12 13:50:37 -0500

Like Eric said, ZoneHVACUnitHeater does have a remove method. To illustrate, just open an irb (or pry session).

First, let's create a model with a ZoneHVACUnitHeater:

model =
fan =, model.alwaysOnDiscreteSchedule)
hc =
uh =, model.alwaysOnDiscreteSchedule, fan, hc)

Now, you can quickly check what methods are available by using object.methods. You can chain grep to match a regex pattern, here a simple one that's case insensitive using the i modifier:

=> [:removeFromThermalZone,

You can remove it, and observe that it also deletes the coils etc.

[1] (main)> model.getZoneHVACUnitHeaters.size
=> 1
[2] (main)> model.getCoilHeatingWaters.size
=> 1
[3] (main)> uh.remove
=> [#<OpenStudio::IdfObject:0x007f990e925de8
[4] (main)> model.getZoneHVACUnitHeaters.size
=> 0
[5] (main)> model.getCoilHeatingWaters.size
=> 0
edit flag offensive delete link more




require 'irb/completion'

then modelObject.<tab><tab>

will cycle through possible methods. This also works if you type part of the method name to narrow down the options.


where tab tab means press the tab key twice.

Kyle Benne's avatar Kyle Benne  ( 2017-01-12 16:47:07 -0500 )edit

Or use Pry, which does that for you, and more, including the possibility to customize your pry profile! (see this for an example)

Julien Marrec's avatar Julien Marrec  ( 2017-01-13 03:16:33 -0500 )edit

answered 2017-01-12 10:13:58 -0500

updated 2017-01-12 10:16:55 -0500

ModelObject inherits methods from the WorkspaceObject class, which is where the remove method lives. Everything, like ZoneHVACUnitHeaters, should also inherit this method, which you can use to remove them from the model.

Note that some HVAC objects will not be 'removable'. But, there is a method isRemovable in HVACComponent that will tell you if an object can be removed.

edit flag offensive delete link more

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

1 follower


Asked: 2017-01-12 10:08:53 -0500

Seen: 287 times

Last updated: Jan 12 '17