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
2

Getting Construction from Surface

asked 8 years ago

joekers's avatar

updated 7 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

updated 8 years ago

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.

Preview: (hide)
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  ( 3 years ago )

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

ericringold's avatar ericringold  ( 3 years ago )

@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  ( 3 years ago )
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  ( 3 years ago )

Thanks Eric, I understand now

wei_zhang's avatar wei_zhang  ( 3 years ago )

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

2 followers

Stats

Asked: 8 years ago

Seen: 230 times

Last updated: Aug 22 '16