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

How to delete ModelObject in OpenStudio with Ruby bindings?

asked 8 years ago

dalin_si's avatar

updated 8 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 8 years ago

updated 8 years ago

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 = OpenStudio::Model::Model.new
fan = OpenStudio::Model::FanConstantVolume.new(model, model.alwaysOnDiscreteSchedule)
hc = OpenStudio::Model::CoilHeatingWater.new(model)
uh = OpenStudio::Model::ZoneHVACUnitHeater.new(model, 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:

uh.methods.grep(/remov/i)
=> [:removeFromThermalZone,
 :isRemovable,
 :remove,
 :removeLifeCycleCosts,
 :remove_instance_variable]

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
  @__swigtype__="_p_openstudio__IdfObject">,
 #<OpenStudio::IdfObject:0x007f990e925d98
  @__swigtype__="_p_openstudio__IdfObject">,
 #<OpenStudio::IdfObject:0x007f990e925d48
  @__swigtype__="_p_openstudio__IdfObject">]
[4] (main)> model.getZoneHVACUnitHeaters.size
=> 0
[5] (main)> model.getCoilHeatingWaters.size
=> 0
Preview: (hide)
link

Comments

1

also.

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.

modelObject.rem<tab><tab>

where tab tab means press the tab key twice.

Kyle Benne's avatar Kyle Benne  ( 8 years ago )

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  ( 8 years ago )
3

answered 8 years ago

updated 8 years ago

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.

Preview: (hide)
link

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 326 times

Last updated: Jan 12 '17