Loading Existing .osm with Python Bindings
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<="" openstudio::model::model="" >="" *'="" 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.
I think you need to add a .get(). Your second attempt seems correct, just add .get(). It's returning an optional without it.
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!
This seemed to work for me:
See docs
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.