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

why the cloned object type changed using the ruby bindings

asked 2017-01-06 10:42:06 -0500

dalin_si's avatar

Hi I want to clone a exist boiler in model by using ruby binding, but after that, I find the modeloject type is diferent, so that I can not add this boiler into a plantloop. how do I change the copy one's object type?

irb(main):115:0> new_boiler = model.getBoilerHotWaters[0].clone(model)
=> #<OpenStudio::Model::ModelObject:0x0000000395a738 @__swigtype__="_p_openstudio__model__ModelObject">
irb(main):116:0> hot_water_loop = model.getPlantLoops[0]
=> #<OpenStudio::Model::PlantLoop:0x0000000390be58 @__swigtype__="_p_openstudio__model__PlantLoop">
irb(main):117:0> hot_water_loop.addSupplyBranchForComponent(new_boiler)
TypeError: Expected argument 1 of type openstudio::model::HVACComponent, but got OpenStudio::Model::ModelObject #<OpenStudio::Model::ModelObje...
        in SWIG method 'addSupplyBranchForComponent'
        from (irb):117:in `addSupplyBranchForComponent'
        from (irb):117
        from C:/Ruby200-x64/bin/irb:12:in `<main>'

the new_boiler is OpenStudio::Model::ModelObject, but the original one is:

irb(main):118:0> model.getBoilerHotWaters[0]
=> #<OpenStudio::Model::BoilerHotWater:0x00000003850ec8 @__swigtype__="_p_openstudio__model__BoilerHotWater">
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-06 11:30:31 -0500

dalin_si's avatar

From the Measure Writer's Reference Guide, it have a clear explanation:

"Several methods in OpenStudio return a "ModelObject" (".clone", ".optionalWorkspaceObjectChoiceValue", etc.). This is fine for many purposes; however, if you want to test if the object returned is of a particular type (e.g., is it a Space or a SpaceType), you will have to try converting the object to those types using the ".to_#{ClassName}" (".to_Space", ".to_SpaceType", etc). "


irb(main):128:0> new_boiler = model.getBoilerHotWaters[0].clone(model).to_BoilerHotWater
=> #<OpenStudio::Model::OptionalBoilerHotWater:0x000000037bda88 @__swigtype__="_p_boost__optionalT_openstudio__model__BoilerHotWater_t">
irb(main):129:0> new_boiler = new_boiler.get
=> #<OpenStudio::Model::BoilerHotWater:0x000000039775e0 @__swigtype__="_p_openstudio__model__BoilerHotWater">
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

Question Tools

1 follower


Asked: 2017-01-06 10:42:06 -0500

Seen: 134 times

Last updated: Jan 06 '17