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 2016-08-22 12:13:15 -0600

joekers's avatar

updated 2017-04-16 14:43:04 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-22 13:00:09 -0600

updated 2016-08-22 15:03:05 -0600

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.

edit flag offensive delete link more

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

Thanks Eric, I understand now

wei_zhang's avatar wei_zhang  ( 2021-07-08 09:39:21 -0600 )edit

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: 2016-08-22 12:13:15 -0600

Seen: 222 times

Last updated: Aug 22 '16