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

How to export OSM to IDF with the command line?

asked 2021-01-14 05:54:22 -0600

Adrien gravatar image

updated 2021-01-14 10:06:19 -0600

I can export my OpenStudio model with the OpenStudioApplication: File / Export / IDF. But I would like to do this from the command line (without running the simulation), is it possible? I can't find it on or when typing openstudio.exe --help or openstudio list_commands.

Oh, I could edit the OSM file to introduce something that would make the simulation instantly fail and then retrieve the IDF from the run directory, but this is a bit cumbersome, I guess there's a better way :)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-01-14 14:40:29 -0600

If you need a one-liner without intermediate files, just call the CLI in a terminal like this:

openstudio -e "vt =; m = vt.loadModel('test.osm').get; ft =; w = ft.translateModel(m);'test.idf', true);"
edit flag offensive delete link more


Thank you! Since I prefer python, I installed your bindings and can also do it with:

python3 -c 'import openstudio;openstudio.energyplus.ForwardTranslator().translateModel(openstudio.osversion.VersionTranslator().loadModel(openstudio.path("test.osm")).get()).save(openstudio.path("test.idf"), True)'
Adrien gravatar image Adrien  ( 2021-01-15 03:40:10 -0600 )edit

Yeah that works too, glad you're testing the python bindings too! I suppose we could also provide a CLI option directly... something like openstudio toidf <file> (or openstudio convert --idf <file>). Feel free to open an enhancement request on if you think that'd be helpful.

Julien Marrec gravatar image Julien Marrec  ( 2021-01-15 06:04:16 -0600 )edit

I don't need the extra CLI option, thanks :-)

Adrien gravatar image Adrien  ( 2021-01-22 05:50:02 -0600 )edit

answered 2021-01-14 08:30:13 -0600

updated 2021-01-14 08:31:49 -0600

Here are two ways to generate the IDF using the OpenStudio CLI without running a simulation:

1. Use an OpenStudio Workflow (OSW)

Create a file called test.osw with the following contents:

  "seed_file": "test.osm"

Then run openstudio run -m -w test.osw, where the -m flag prevents the simulation from running. You will find the IDF at run/in.idf.

2. Use the OpenStudio SDK

Create a simple ruby script called generate_idf.rb with the following contents:

vt =
model = vt.loadModel("test.osm")).get
ft =
model_idf = ft.translateModel(model)"test.idf", "w") { |f| f << model_idf.to_s }

Then run openstudio generate_idf.rb. It will create a test.idf file next to your test.osm file.

edit flag offensive delete link more


Awesome, thanks!

Adrien gravatar image Adrien  ( 2021-01-14 08:34:52 -0600 )edit

Prefer using'path.idf', true) rather than The second argument (boolean) is whether you allow overwrite of an existing file or not.

Julien Marrec gravatar image Julien Marrec  ( 2021-01-14 14:39:01 -0600 )edit

A long time ago, I was told that .to_s was much faster than .save. But I forget the exact reason (sorting objects?) and don't know whether it still applies.

shorowit gravatar image shorowit  ( 2021-01-14 14:49:52 -0600 )edit

It seems to be faster, yet I wouldn't recommend the to newcomers :)

require 'openstudio'
require 'benchmark'

m = OpenStudio::Model::exampleModel()
ft =
w = ft.translateModel(m)'test_save.idf', true)'test_open.idf', true)

n = 100 do |x|"save:")   { n.times do   ;'test_save.idf', true); end }"") { n.times do   ;"test_open.idf", "w") { |f| f << w.to_s }; end }
Julien Marrec gravatar image Julien Marrec  ( 2021-01-14 14:58:19 -0600 )edit


                 user     system      total        real
    save:     1.024476   0.268156   1.292632 (  1.292821)  0.892978   0.015530   0.908508 (  0.917008)
Julien Marrec gravatar image Julien Marrec  ( 2021-01-14 14:58:28 -0600 )edit

Your Answer

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

Add Answer


Question Tools

1 follower


Asked: 2021-01-14 05:54:22 -0600

Seen: 28 times

Last updated: Jan 15