2

Getting Construction from Surface

I'm trying to add an outer layer of a material to specific surfaces. I currently have a loop that cycles through all the surfaces and singles out those that I want to modify. However, in order to insert a layer, I need the Construction object assigned to that surface. I've notice the Construction parameter associated with a surface returns a Construction base object and not a Construction. How do I obtain the Construction object?

joekers's avatar
263
joekers
asked 2016-08-22 12:13:15 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2017-04-16 14:43:04 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

You can cast the ConstructionBase to a Construction by using to_Construction:

construction = surface.construction
if not construction.empty? and not construction.get.to_Construction.empty?
  construction = construction.get.to_Construction.get
end

Which is one way to do it.

ericringold's avatar
10.6k
ericringold
answered 2016-08-22 13:00:09 -0500, updated 2016-08-22 15:03:05 -0500
edit flag offensive 0 remove flag delete link

Comments

I happened to see this answer. Hi Eric, I did not find to_Construction in OpenStudio SDK. Could you please help me where you can find the documentation about it?

wei_zhang's avatar wei_zhang (2021-07-06 19:04:57 -0500) edit

@wei_zhang see this section of the Measure Writer's Guide: https://nrel.github.io/OpenStudio-use...

ericringold's avatar ericringold (2021-07-07 10:01:42 -0500) edit

@Eric Ringold Thanks Eric, I have a further question. In Measure's Writer's Guide "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}"". But the .clone would copy a object, why need we check it again after copying? because we do not trust .clone in Ruby?

I tried to use setLayer without to_Construction, got error undefined method setLayer for # .

That means we have to use ".to_#{ClassName}" as .clone can not completely copy ModelObject?

wei_zhang's avatar wei_zhang (2021-07-08 08:27:34 -0500) edit
1

The clone method is implemented in the ModelObject class, which is the parent class that all OpenStudio model objects inherit from, and returns a copy of the original object as a ModelObject instance that must be cast back to the child class to access the child class's methods.

ericringold's avatar ericringold (2021-07-08 09:36:26 -0500) edit

Thanks Eric, I understand now

wei_zhang's avatar wei_zhang (2021-07-08 09:39:21 -0500) edit
add a comment see more comments