Import Sketchup scenes to Layout Ruby API

layout

#1

Hi everyone! How can I import my Sketchup scenes to Layout with Ruby Api? I need to put some scenes to my Layout document and I don’t know how.


#2

https://help.sketchup.com/en/layout/inserting-sketchup-model-your-document
https://help.sketchup.com/en/layout/editing-sketchup-models-view-and-style-settings-layout

Within LayOut, go to File then Insert. Find and select the skp model that you would like to use.
Within SketchUp, go to File then Send to LayOut… Once in LayOut select the template that you would like to use. Select the desired scene for each viewport with the SketchUp Model tray in Layout.

(To my knowledge, LayOut Ruby API is not useful yet and/or not in common enough use.)


#3

The LayOut API is not for controlling the LayOut application (functions, user interface, import), but currently only for editing LayOut files (.layout) from within SketchUp. The Ruby API is (currently) located within SketchUp.

It hasn’t been used a lot, so you won’t find many people with experience with it. But the general procedure is to open SketchUp → Window → Ruby Console (or Ruby Console+), and load the layout document.

I would expect you can use it somewhat similar to this:

# Get a reference to your current (saved) SketchUp model:
model = Sketchup.active_model
# Open your LayOut file.
doc = Layout::Document.open("C:/path/to/document.layout")
# Create an instance of the model in LayOut (model.path should contain the file path of the saved .skp)
bounds = Geom::Bounds2d.new(1, 1, 3, 3)
layout_model = Layout::SketchUpModel.new(model.path, bounds)
# Add the model to the first layer on the first page
doc.add_entity(layout_model , doc.layers.first, doc.pages.first)
# Select the same scene as in SketchUp and render a view of the model
current_sketchup_scene = model.pages.selected_page
current_sketchup_scene_index = model.pages.index(current_sketchup_scene)
layout_model.current_scene = current_sketchup_scene_index 
layout_model.render

#4

Just for a general FYI, … the SketchUp Extensibility Team has an example extension that does this automatically. (It is a compiled C extension, but stills does what the OP asked but creates a new LayOut file. The OP seems be be asking to import model scenes as new viewports into an existing .layout file. The extension example linked below will not do this)

https://extensions.sketchup.com/en/content/create-layout-file


#5

Hi! thanks for your help but this code gets me an error in the line:
current_sketchup_scene_index = model.pages.index(current_sketchup_scene)
Error:
Error: #<NoMethodError: undefined method index' for #<Sketchup::Pages:0x00015396a34ce8>>

I think the class ‘Pages’ from module ‘Sketchup’ doesn’t have any method called ‘index’. Anyway I have tried to put the index manually and it doesn’t work still.
On the other hand, the method ‘render’ doesn’t seem to work. When I use ‘render’ should I get the view of Sketchup in the layout document?

Thanks