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

Loading Existing .osm with Python Bindings

asked 2022-02-07 17:21:45 -0500

updated 2022-02-07 18:28:48 -0500

I'm trying to load an OSM that I developed in the application as an object in Python, however, I haven't been able to get it to load in correctly.

I've tried both:

     building = openstudio.model.Model_load(osm_path)

and

     building = openstudio.model.Model.load(osm_path)

When I use print(building) I get this:

openstudio.openstudiomodelcore.OptionalModel; proxy of <swig object="" of="" type="" 'boost::optional&lt;="" openstudio::model::model="" &gt;="" *'="" at="" 0x00000277a42c7600<="" p="">

I'm not super familiar with Ruby so maybe my issue is just trying to convert from the SDK documentation (https://openstudio-sdk-documentation....) to Python notation. I saw this post (https://unmethours.com/question/57173...) and have found that openstudio.model.Model() and openstudio.model.exampleModel() seem to work just fine.

I feel like I'm overlooking something small but I just can't figure out what it is. I appreciate any insight from folks who've started using Python in their OpenStudio workflow.

edit retag flag offensive close merge delete

Comments

1

I think you need to add a .get(). Your second attempt seems correct, just add .get(). It's returning an optional without it.

bonnema's avatar bonnema  ( 2022-02-08 09:17:29 -0500 )edit

It works! Thanks! Do you happen to know how to use the version translator as well? This works with a file that I manually convert with the application from version 3.1.0 to 3.3.0. I have some old models that I haven't moved to the new version and I'd like to work with them in Python without having to open the app each time.

I'm trying:

translator = openstudio.osversion.VersionTranslator

building = translator.loadModel(osm_path)

but get a type error:

TypeError: Wrong number or type of arguments for overloaded function 'VersionTranslator_loadModel'.

Cheers!

GFlechas's avatar GFlechas  ( 2022-02-08 11:40:49 -0500 )edit
1

This seemed to work for me:

osm_path = openstudio.path('tmp.osm')
vt = openstudio.osversion.VersionTranslator()
new_osm = vt.loadModel(osm_path).get()
bonnema's avatar bonnema  ( 2022-02-08 12:16:32 -0500 )edit
1

See docs

bonnema's avatar bonnema  ( 2022-02-08 12:18:09 -0500 )edit

Ok I'm catching on! Thank you for your help. I was passing in osm_path using a file path created by the "os" package in the form os.path.join(current_dir,osm_name). This works fine for loading in a current model, but doesn't work for the version translator.

GFlechas's avatar GFlechas  ( 2022-02-08 12:48:18 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2022-03-15 14:38:46 -0500

For anyone who stumbles into a similar issue to me. I've put together a Python Jupyter notebook as I've experimented with the python bindings. Hopefully, it's helpful for others getting started with the Python bindings.

Github-load_model_add_ruleset_notebook.ipynb

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Question Tools

1 follower

Stats

Asked: 2022-02-07 17:21:45 -0500

Seen: 240 times

Last updated: Mar 15