How to export multiple 2d views at once

Hi,

I’m looking for a way (i’m thinking ruby code or an extension) to export multiple views with a single action. I have hundreds of .skp that I need to export to .png, (viewFront:, viewLeft/Right:, viewTop:, viewIso:) I know I could make a scene in each view and export animation, but it feels too repetitive after a while…

I found this code:

model  = Sketchup.active_model
scenes = model.pages
@view = model.active_view
@path = chosen_folder = UI.select_directory(title: "Select Export Folder")	

def scene_img(name)
  keys = {
:filename => "#@path/#{name}.png",
:antialias => true,
:compression => 0,
:transparent => true
  }
  @view.write_image keys
end

scenes.each do |s|
scenes.selected_page = s
name = s.name
scene_img(name)
end

it kind of does what I want, but still with scenes… im not good with code but i assume a ruby code would be doable, if it is possible to name the images like filename_view.png that would be perfect.

Thanks / A noob

1 Like

You can change the camera of the view directly:

camera = Sketchup::Camera.new([5, 5, 9], [5, 10, 0], Z_AXIS)
view = Sketchup.active_model.active_view
view.camera = camera
# Camera
  Sketchup.send_action('viewUndo:')  ## Previous
  Sketchup.send_action('viewRedo:')  ## Next
  Sketchup.send_action('viewTop:')  ## Top  ### ⌘1
  Sketchup.send_action('viewBottom:')  ## Bottom  ### ⌘2
  Sketchup.send_action('viewFront:')  ## Front  ### ⌘3
  Sketchup.send_action('viewBack:')  ## Back  ### ⌘4
  Sketchup.send_action('viewLeft:')  ## Left  ### ⌘5
  Sketchup.send_action('viewRight:')  ## Right  ### ⌘6
  Sketchup.send_action('viewIso:')  ## Iso  ### ⌘7
  Sketchup.send_action('viewParallelProjection:')  ## Parallel Projection
  Sketchup.send_action('viewPerspective:')  ## Perspective
  Sketchup.send_action('viewTwoPointPerspective:')  ## Two-Point Perspective

john

(Moving to Ruby API subcategory.)

Please post using code delimiter lines per: [How to] Colourize code on the forum? (wiki)

FYI, There is an error in your code …

:filename => "#@path/#{name}.png",

For string interpolation, you need to use #{ ... } to delimit the eval expression, so correct is:

:filename => "#{@path}/#{name}.png",

It is also a good thing to post a link to where the code came from.


We’ve covered this is other threads. I’ll see if I can search them up …

Here is one example I wrote …