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

Create Openstudio model Object from an .osm File

asked 2016-07-24 22:35:17 -0600

chriswmackey's avatar

updated 2016-07-26 06:10:15 -0600

I know that this question is so incredibly simple but I have been scouring this forum and looking through OpenStudio measures for the last hour without any luck.

I have a .osm file that I have created and saved and I want to turn this .osm file into an OpenStudio Model Object so that I can edit it with OpenStudio SDK. I see that I can initialize a model object from an IDF file but there doesn't seem to be a class method for initializing such a model object from an .osm.

I am sure that there must be a way but it's hiding in plain sight from me. I am using OpenStudio C# bindings but any example code that uses the OpenStudio SDK would be a great answer.

Thank you,

edit retag flag offensive close merge delete

Comments

1

Hey @chriswmackey, welcome to UH! You should really post your updates as an answer (perfectly fine to answer your own questions).

(Also, please refrain from creating new tags unless you really think it's missing)

Julien Marrec's avatar Julien Marrec  ( 2016-07-25 03:30:03 -0600 )edit
1

The optional pointer wrappers are part of OpenStudio's initiation/hazing process. You will come to accept them. You have to work through the other stages of optional pointer grief though.

__AmirRoth__'s avatar __AmirRoth__  ( 2016-07-25 05:57:00 -0600 )edit

Julien and Amir, Thanks for the info. I have moved my answer out of the question part. I realize now why it's good to put it down there as your solution, Julien, definitely deserves more positive votes. I might just refrain from using the tags until I understand them more. Is there a list of tags that is already established, Julien?

chriswmackey's avatar chriswmackey  ( 2016-07-25 09:40:23 -0600 )edit

Whenever you start typing a tag, a list of possible ones pops up. Just make sure you use one that's already defined

Julien Marrec's avatar Julien Marrec  ( 2016-07-25 09:59:47 -0600 )edit

Makes sense. Thank you, Julien!

chriswmackey's avatar chriswmackey  ( 2016-07-25 11:03:50 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2016-07-25 03:37:44 -0600

The typical way to load a model when using the API is to call the VersionTranslator object, this will upgrade any model created in an earlier version to the specific version you're using.

I've personally created a helper function that I load whenever I launch a new Pry (ruby) session. Syntax below is in ruby, but easily adapted to your specific language bindings.

# Helper to load a model in one line
def osload(path)
  translator = OpenStudio::OSVersion::VersionTranslator.new
  ospath = OpenStudio::Path.new(path)
  model = translator.loadModel(ospath)
  if model.empty?
      raise "Path '#{path}' is not a valid path to an OpenStudio Model"
  else
      model = model.get
  end  
  return model
end

This allows me to do model = osload('mymodel.osm'), which I find to be a big time saver considering how many times I do this in a given modeling day.

See the Measure Writing guide, Model and Workspace Creation, Loading, the "Load Existing Model" especially.

edit flag offensive delete link more
3

answered 2016-07-25 09:36:35 -0600

chriswmackey's avatar

SOLUTION FROM THE PERSON POSTING THE QUESTION: I realized something hiding in plain sight: there's a load() method under 'Static Public Member Functions' in the page that I linked to, which seems to be made for converting .osm files to model objects. This code finally worked for me:

import OpenStudio
osmPath = "C:\MyModels\model.osm"
model = OpenStudio.Model().load(OpenStudio.Path(osmPath)).get()

All of this said, I think Julien's solution is better as it is able to deal with .osm files generated from different versions of OpenStudio. Thanks for the insightful answer, Julien!

edit flag offensive delete link more

Comments

ultimately, don't forgot to mark an answer as accepted if you're satisfied (green check mark below the up/down vote buttons). That tells people the thread has been resolved

Julien Marrec's avatar Julien Marrec  ( 2016-07-25 10:07:14 -0600 )edit

Good Morning Chris, my name is Josh Talbert. Hey I have a live question going regarding this but I wondered if you could give me direct feedback. I have written a measure to load an OSM from the measure directory, and my measure seems to partially work. I can find the resource location, it opens the file location, (and reports out the OSM text) but it doesn't seem to pass the loaded OSM forward into the simulation. I have added in the forward translator stuff too, but it doesn't seem to be working. Would you please comment on what might be wrong? Thank you.

pow_skier's avatar pow_skier  ( 2018-05-15 10:25:20 -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

1 follower

Stats

Asked: 2016-07-24 21:54:54 -0600

Seen: 965 times

Last updated: Jul 25 '16