First time here? Check out the Help page!

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 8 years ago

joekers's avatar

updated 7 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 8 years ago

Adam Hilton's avatar

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

Preview: (hide)
link
2

answered 8 years ago

updated 8 years ago

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
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: 193 times

Last updated: Sep 07 '16