Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

Iterating through OpenStudio Objects to get their "Types" and "Attributes"

asked 2022-11-17 10:53:43 -0600

updated 2022-11-17 16:37:52 -0600

Hi All,

For context this is being done using Python. I'm trying to see if there's a built-in method where I can load an existing OpenStudio model, use specific_object = osm.getObject(an_object_handle).get() to isolate a specific object (where osm is the whole model), and then pick apart and inspect what's in the object. If I use print(specific_object) I get a nice human-readable block of text. However I can't seem to figure out how to iterate through these fields beyond just specific_object.name().

I'd like to iteratively return if possible the type of object (Space, Thermal Zone, Construction, etc.), and its attributes. Like in the case of a space, returning Space Type Name, Default Construction Set Name, Default Schedule Set Name, etc.

I put types and attributes in quotes in the title because I think the nomenclature in OpenStudio is a little different which might be part of my problem.

I really appreciate any suggestions you all might have. I think if all else fails I could use str(specific_object) to get that human-readable output and then parse through that with other python tools. I just wasn't sure if there was a built-in way. My end goal for this project is to generate some reporting for myself about the model so I don't necessarily need to hang onto the OpenStudio objects themselves nor am I necessarily trying to change them. However, it would be nice to know what options I have should I want to later.

Thanks!

edit retag flag offensive close merge delete

Comments

I'm having a very similar issue. In python lots of objects can have their attributes described by object.__dict__ but that has not been implemented here and it's frustrating.

clima337's avatar clima337  ( 2023-10-19 13:33:17 -0600 )edit

I think a wrapper model is probably needed. Something that takes the openstudio module and provides added context and documentation for the functions and objects. You could subclass the objects and then add documentation and description. It's not a small undertaking by any stretch but may be the best way to pythonify the openstudio module.

GFlechas's avatar GFlechas  ( 2023-11-03 16:54:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-12-05 22:45:25 -0600

updated 2022-12-06 09:15:20 -0600

I totally misread your question; I am leaving my original answer below just because I had fun figuring that out.

You are looking for the OpenStudio SDK. Take a look at the documentation for the FanOnOff class. There are different methods to get everything about the fan, take a look at the example code below where I print the fan pressureRise parameter.

from openstudio import model
m = model.Model()
f = model.FanOnOff(m)
pressure_rise_si = f.pressureRise()
print('The fan Pressure Rise in Pa is ' + str(pressure_rise_si))

Output

The fan Pressure Rise in Pa is 300.0

You can get any parameter from a fan using similar methods, take a look at the SDK for the specific documentation.

---- Original answer

Hmm interesting, I would like to ask you back what is the reason why you would do this. The following Python code should do what you are asking if I understand what you want to do.

# Create a fan
from openstudio import model
m = model.Model()
f = model.FanOnOff(m)
#  Get the fan iddObject
obj = f.iddObject()
fields = obj.numFields()
for i in range(fields):
  print(f.getField(i))

Output:

{0fae4eb3-fe16-4c05-94f7-4ed150857507}
Fan On Off 1
{2f817562-e016-4118-9091-e4f096e2b345}
0.6
300
autosize
0.8
1


{668676fe-a69f-4db3-8e07-9953fa12b2d4}
{eb20ba76-8c87-412f-be6f-8d4b4c8af830}
edit flag offensive delete link more

Comments

Hi Luis, I was looking through my old posts for some info and realized I didn't respond to this. I was working on a project visualizing model connections. Your original response was actually more in line with what I was trying to accomplish, so thanks for taking the time to answer my question! It was very helpful!

GFlechas's avatar GFlechas  ( 2024-08-14 20:37:43 -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: 2022-11-17 10:53:43 -0600

Seen: 232 times

Last updated: Aug 14