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)