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

Getting Class of Object

asked 2016-09-07 12:29:52 -0500

joekers's avatar

updated 2017-04-16 14:42:36 -0500

I'm iterating through an array of ModelObjects and want to single out those that are of class WaterHeater? Is there a method that returns the class of the current object? Not sure how to word this question. When I get the class of the object, it is ModelObject. However, I know from looking at the model that it's class WaterHeater. Whenever I use the method supplyComponents, it returns the component as a model object.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-09-07 13:02:52 -0500

Adam Hilton's avatar

Using .name under IddObject will return a string of the OS object name.

edit flag offensive delete link more
2

answered 2016-09-07 12:56:00 -0500

updated 2016-09-07 13:10:06 -0500

There are a few ways to do this:

modelObjects = model.getHVACComponents

waterHeaters = []
modelObjects.each do |obj|
  if obj.to_WaterHeaterMixed.is_initialized
    obj = obj.to_WaterHeaterMixed.get #converts the object to a waterHeaterMixed object
    waterHeaters << obj
  end
end

waterHeaters.each do |obj|
  puts "#{obj.name}"
  puts "#{obj.class}"
end

#Alternatively 
waterHeaters = model.getWaterHeaterMixeds
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

Careers

Question Tools

1 follower

Stats

Asked: 2016-09-07 12:29:52 -0500

Seen: 161 times

Last updated: Sep 07 '16