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

Revision history [back]

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!(/\\/, '/')
  puts idf_path
  #idf_importer.load_file(idf_path, '')
  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)
  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...

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!(/\\/, '/')
  puts idf_path
  #idf_importer.load_file(idf_path, '')
  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)
  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

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!(/\\/, '/')
  puts idf_path
  #idf_importer.load_file(idf_path, '')
   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

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(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)

  # Dirty old town, ooooooh dirty old town.
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events

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

  # sleep(10)
  # Export after 10 seconds.
  #id = UI.start_timer(10, false) {
    skp_model = Sketchup.active_model
    view = skp_model.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/Test/#{model_name.sub('.idf','')}.jpg"
  #}
  #UI.stop_timer id

end

Example output image:

5ZoneAirCooled

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(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)

  # Dirty old town, ooooooh dirty old town.
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events
  OpenStudio::Plugin.process_events

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

  # sleep(10)
  # Export after 10 seconds.
  #id = UI.start_timer(10, false) {
    skp_model = Sketchup.active_model
    view = skp_model.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/Test/#{model_name.sub('.idf','')}.jpg"
  #}
  #UI.stop_timer id

end

Example output image:

5ZoneAirCooled

Output

From Adrien, who apparently doesn't get an error with my update and who uses XnView to place the image on one file:

image description)