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

Converting .idf to JPEG in batchmode

asked 2017-02-22 08:05:46 -0600

AdB's avatar

updated 2017-02-22 14:59:08 -0600

I have generated a pool of idf file through an optimization process while modifying facade characteristics (notably the position and length of the overhang and dimensions of the windows). I would like to have a graphical rendering for each idf. There is between hundred and several thousand idf files so I am searching for a batch processing method.

Can I do that though ruby scripting and open studio? Or using energyplus dxf export capability?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-02-22 16:38:10 -0600

updated 2017-02-23 09:40:08 -0600

Considering that Sketchup can export a JPEG image of the current view and has a ruby console, and considering that OpenStudio has a sketchup plugin and can load IDF file, I figured there was an easy way to do this.

I've got a work in progress using Sketchup and OpenStudio. The following example tries to load two E+ example files and export to a JPEG image.

Open Sketchup, enable the ruby Console (Window > Ruby Console), and try to following (modify the path as needed)

# Change to your system
base_path = '/Applications/EnergyPlus-8-6-0/ExampleFiles/'
model_names = ['5ZoneAirCooled.idf', '1ZoneUncontrolled.idf']


model_names.each do |model_name|
  idf_path = base_path + model_name
  idf_path.gsub!(/\\/, '/')

  workspace = OpenStudio::Plugin.model_manager.workspace_from_idf_path(idf_path)
  if not workspace 
    return(0)
  end

  openstudio_model, errors, warnings, untranslated_idf_objects = OpenStudio::Plugin.model_manager.model_from_workspace(workspace)
  # def attach_openstudio_model(openstudio_model, skp_model, path = nil, save_path = false , do_zoom = true, errors = nil, warnings = nil, untranslated_idf_objects = [])

  OpenStudio::Plugin.model_manager.attach_openstudio_model(openstudio_model, Sketchup.active_model, nil, false, true)

  # Maybe you'd want to position the camera correctly here...

  # Export the current view to a JPEG
  skmodel = Sketchup.active_model
  view = skmodel.active_view
  # http://ruby.sketchup.com/Sketchup/View.html#write_image-instance_method
  # Change output path to your folder. You can also pass a hash specifying options such as width and height
  status = view.write_image "/Users/julien/Desktop/#{model_name.sub('.idf','')}.jpg"
end

If I run the inside of the loop line by line, it works perfectly. The problem that I have is that when I use the loop on model_names it crashes with the following error:

ERROR:
NoMethodError
undefined method `rendering_mode=' for nil:NilClass
BACKTRACE:
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/interfaces/ModelInterface.rb:962:in `block in attach_openstudio_model'
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/PluginManager.rb:235:in `call'
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/PluginManager.rb:235:in `block in process_events'
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/PluginManager.rb:228:in `each'
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/PluginManager.rb:228:in `process_events'
/usr/local/openstudio-2.0.0/SketchUpPlugin/openstudio/sketchup_plugin/lib/PluginManager.rb:287:in `block in start_event_processing'
SketchUp:1:in `call'

I'm thinking it's a problem of waiting for one command to complete before issuing the next one...

Here's the line where it goes awry: ModelInterface.rb#L962

Edit:

Here's an imperfect quick fix. It will produce rendered images, but once in a while there's a new error that pops up you only have to hit "Enter" on your keyboard and it'll still export the image correctly. It's going to get annoying for 1000 IDF, but I guess you could train a monkey to do this...

# Change to your system
base_path = '/Applications/EnergyPlus-8-6-0/ExampleFiles/'
model_names = ['5ZoneAirCooled.idf', '1ZoneUncontrolled.idf', '5ZoneCoolBeam.idf', '5ZoneElectricBaseboard.idf', 'Furnace.idf']

model_names.each do |model_name|
  puts "\n\n========== #{model_name} =========\n"
  idf_path = base_path + model_name
  idf_path.gsub!(/\\/, '/')

  workspace = OpenStudio::Plugin.model_manager.workspace_from_idf_path(idf_path)
  if not workspace 
    return(0)
  end

  openstudio_model, errors, warnings, untranslated_idf_objects = OpenStudio::Plugin.model_manager.model_from_workspace(workspace)

  # def attach_openstudio_model ...
(more)
edit flag offensive delete link more

Comments

My little finger (or is it @macumber?) tells me it's happening around here: https://github.com/NREL/OpenStudio/bl...

Julien Marrec's avatar Julien Marrec  ( 2017-02-22 16:52:49 -0600 )edit

You proposal allowed me to do the conversion with a wire rendering. I have the same rendering_mode error. I am not used to Ruby so I do not have the means to investigate deeper. Thank you very much

AdB's avatar AdB  ( 2017-02-23 04:16:08 -0600 )edit

I ve just tried with the update and it works perfectly, I don't have the error you mention. Can I add a figure ?

AdB's avatar AdB  ( 2017-02-23 07:46:03 -0600 )edit

@Adrien Brun, I added your image to my answer (since your post below cannot qualify as an answer). Glad to see you don't have an error, I'm not sure why you don't while I do, maybe it's because your model is smaller or something.

Feel free to upvote this answer if helpful and mark this answer as accepted if it solved your problem.

Julien Marrec's avatar Julien Marrec  ( 2017-02-23 09:42:44 -0600 )edit
1

answered 2017-02-22 13:20:33 -0600

updated 2017-02-22 13:38:31 -0600

I have never used it but you can try The QCAD command line tools which can convert DXF files to a variety of bitmap formats.

edit flag offensive delete link more

Comments

2

Thank you Jason, I have a look on the qcad dwg2bmp documentation. Unfortunately it is not possible to give information on the point of view so it probably limited to 2D dwf or dxf.

AdB's avatar AdB  ( 2017-02-22 14:25:30 -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: 2017-02-22 08:05:46 -0600

Seen: 410 times

Last updated: Feb 23 '17