4

Convert a cloned object to the source class

I want to clone an existing ZoneHVACComponent (such as a ZoneHVACLowTempRadiantVarFlow or a ZoneHVACWaterToAirHeatPump) and then add it to a thermal zone. However, using the clone method on an object returns a ModelObject and I cannot access the addToThermalZone method in the cloned object unless I use the ".to_#{ClassName}" method to convert it to the same class as the source.

I am looking to be able to use use the ".to_#{ClassName}" method no matter the source object Class without having to specify a case statement or something similar. I could write the full case statement but I feel like there is a more elegant solution.

Luis Lara's avatar
2.1k
Luis Lara
asked 2019-04-25 13:41:46 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

4

@Julien Marrec to the rescue!

See his to_actual_object method here:

https://unmethours.com/question/17616...

Oh, also in your case, since addToThermalZone is a ZoneHVACComponent method, you wouldn't necessarily have to cast the cloned ModelObject down to the specific 'actual' object to use it. You could rather just cast to_ZoneHVACComponent.

ericringold's avatar
10.6k
ericringold
answered 2019-04-25 13:57:45 -0500, updated 2019-04-25 14:02:35 -0500
edit flag offensive 0 remove flag delete link

Comments

Both ways worked, I thought I tried tried the to_ZoneHVACComponent method before but maybe my syntax was wrong.

Luis Lara's avatar Luis Lara (2019-04-25 14:22:35 -0500) edit
add a comment see more comments