3

Getting Class of Object

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.

joekers's avatar
263
joekers
asked 2016-09-07 12:29:52 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2017-04-16 14:42:36 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

2

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

Adam Hilton's avatar
3.5k
Adam Hilton
answered 2016-09-07 13:02:52 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
2

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
mdahlhausen's avatar
9.5k
mdahlhausen
answered 2016-09-07 12:56:00 -0500, updated 2016-09-07 13:10:06 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments