# Extension Ruby help -\> send to layout

**URL:** <https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422>\
**Category:** Ruby API\
**Tags:** layout, layoutapi\
**Created:** [March 15, 2026, 12:02pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422 "2026-03-15T12:02:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![napperkt](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/napperkt/32/141915_2.png) [@napperkt](https://forums.sketchup.com/u/napperkt)\
**Post date:** [March 15, 2026, 12:02pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/1 "2026-03-15T12:02:30Z")

</div>

I have recently dabbled rather successfully with creating a very specific extension for our company. It streamlines a whole bunch of steps that we usually need to take to create specific drawing details. I managed to create it with the help of Antigravity + Gemini / Claude. It’s been an amazing journey. Now I’ve run against a wall with a specific feature which seemed easy at first but it’s simply not working.

 ![Bildschirmfoto 2026-03-15 um 12.58.55](https://global.discourse-cdn.com/sketchup/original/4X/8/b/8/8b84cbd6533391314bf0b3468e56bf18f3293bc7.jpeg)

I have created a folder with Layout-Files  
In the extension I point to that folder in the setting section  
The extension reads the folder, finds all the Layout-files and builds a “send to \_\_\_\_” button per file.  
When you click on the button it is supposed to check if the sketchup file is saved and then “send it to layout” → meaning the specific layout file the button was created for. So if I have DIN A1 sheet with our company logo and stuff all set up correctly there will be a button hat creates a new layout file based on the template and adds the current sketchup file / scene to it.

I know this is possible. 🙂

But I keep getting versions of this error:

 ![image](https://global.discourse-cdn.com/sketchup/original/4X/0/1/d/01daa2211a12c63429f979eecaeb05a47f26b845.png)

Here is the summarized code I am trying to use.

```auto
# 1. Open the template file
doc = Layout::Document.open("/path/to/template.layout")
page = doc.pages.first

# 2. Define the viewport bounds (paper size minus 1-inch margin)
info = doc.page_info
margin = 1.0
bounds = Geom::Bounds2d.new(margin, margin,
                             info.width - 2.0 * margin,
                             info.height - 2.0 * margin)

# 3. Create the SketchUp model viewport
viewport = Layout::SketchUpModel.new("/path/to/model.skp", bounds)

# 4. Set the scene (1-based index into model.pages)
viewport.current_scene = 3 # e.g. third scene tab

# 5. Resolve a layer to place the entity on
# page.layer_instances.first is nil for some documents → fallback
target_layer = page.layer_instances.first || doc.layers.first

# 6. Add viewport to the document, save, and open
doc.add_entity(viewport, target_layer, page)
doc.save("/path/to/output.layout")
UI.openURL("file:///path/to/output.layout")

```

Any pointers or (code) examples of how I could get this to work?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 15, 2026, 12:38pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/2 "2026-03-15T12:38:27Z")

</div>

> [@napperkt](#):
>
> ```ruby
> # 1. Open the template file
> doc = Layout::Document.open("/path/to/template.layout")
> page = doc.pages.first
> 
> ```

If you are using a template file to base a **new** document upon, then you use [`Layout::Document::new`](https://ruby.sketchup.com/Layout/Document.html#initialize-instance_method) **not** [`Layout::Document::open`](https://ruby.sketchup.com/Layout/Document.html#open-class_method).

Otherwise you will be modifying the template file rather than a new file.

Also, the template file could have it’s file locked if you did this previously, which could be resulting in the “file does not exist” error.

- **Aside** : I had reported that the `Layout` API does **not** have a `close` method for the `Layout::Document` class, therefore once you open a document file, it will remain open and locked for the session. (Hopefully, the file handle will be released when SketchUp is closed.)

* * *

In other news …

You can use Ruby core [`File`](https://docs.ruby-lang.org/en/3.2/File.html) class method to test if the user has permissions for your template folder path.

---

<div class="post-metadata">

**Author:** ![napperkt](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/napperkt/32/141915_2.png) [@napperkt](https://forums.sketchup.com/u/napperkt)\
**Post date:** [March 15, 2026, 2:14pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/3 "2026-03-15T14:14:17Z")

</div>

Hi Dan - thank you so much for your input. I have changed the code to

doc = Layout::Document.new(template\_path)

and cleaned up the code the best I can. **I actually managed to get this to work now** with SOME Layout files and not with others.

VERY interesting. So I did some testing. I opened the working Layout file, modded it a bit and changed saved it again (save as template - not sure if this makes a difference but better safe then sorry…)

Tested. All good. Modded a bit further. saved and tested. All good. Took the content of the layout file that DOESN’T work and copy pasted into the layout file that was working. Tested - ERROR! 🙂

So there is something in that layout file that Sketchup doesn’t like. Mhhhh… Next try - copied element for element from one layout file to the other until I found the “bad boy” - it was the linked Excel Sheet.

 ![image](https://global.discourse-cdn.com/sketchup/original/4X/b/2/f/b2fd63e7bed2ad33a3e2c94cbe3a7089e1e76a1f.jpeg)

Very, very interesting. Where does that leave us? 🙂 Is a layout template file not allowed to contain linked elements?

I might need to give up the “send to layout” idea. I was a bit to enthusiastic - or rather - not clear enough with my intentions to myself. I now realize what I want to do is to immitate my current workflow. We have layout files that we copy to a project. They are set up very deliberately . We open them, go to reference and update the reference of the Sketchup file with that of the current project and the reference of the Excel-sheet with that of the current project. This sets up everything rather nicely. Not sure if this can actually be achieved via Ruby script.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 15, 2026, 3:04pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/4 "2026-03-15T15:04:07Z")

</div>

> [@napperkt](#):
>
> We have layout files that we copy to a project. They are set up very deliberately . We open them, go to reference and update the reference of the Sketchup file with that of the current project and the reference of the Excel-sheet with that of the current project. This sets up everything rather nicely. Not sure if this can actually be achieved via Ruby script.

**Unfortunately** , the update method for a model viewport is still missing from the API, as well as the method to import external table files.

From the official API Issue Tracker at GitHub:

> <https://github.com/SketchUp/api-issue-tracker/issues/590>
>
> \# Use Case
> A SketchUp Extension wants to modify a SketchUp file which is refere…nced by a Layout file.
> The Layout Document needs to be told to update it's SketchUpModel Entities.
> After that a PDF Export of the updated Layout file is performed.
> 
> \# Missing Feature
> To update the SketchUpModel references in the Layout Document currently there is no option to perform a "Update Model References" like there is in the UI.
> 
> \## Example function names
> \`Layout::SketchUpModel.update\_model\_references\`
> and 
> \`Layout::SketchUpModel.relink\_model\_references\`
> 
> \## Current Workaround
> A Workaround to this is to remove the SketchUpModel Entity and to insert it again.
> 
> \*\*However that workaround is buggy\*\* as described \[in this bug report\](https://github.com/SketchUp/api-issue-tracker/issues/589)

> <https://github.com/SketchUp/api-issue-tracker/issues/306>
>
> see: https://forums.sketchup.com/t/layout-import-table-data-through-api/99627
> T…he current Layout API does not allow one to import external table data like the GUI allows one to do.

---

<div class="post-metadata">

**Author:** ![napperkt](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/napperkt/32/141915_2.png) [@napperkt](https://forums.sketchup.com/u/napperkt)\
**Post date:** [March 15, 2026, 3:20pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/5 "2026-03-15T15:20:28Z")

</div>

Ok - got it. Well - fingers crossed that the API will be expanded at one point or the other! 🙂 Crazier things have happened! I’ll use what I have now for a “simple” callout to Layout and shelf my idea of sending it of to our more complex files for now.

Thank you so much. I would have chased that rabbit for a long, fruitless time!

---

<div class="post-metadata">

**Author:** ![MikeWayzovski](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/mikewayzovski/32/98346_2.png) [@MikeWayzovski](https://forums.sketchup.com/u/MikeWayzovski)\
**Post date:** [March 15, 2026, 5:16pm UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/6 "2026-03-15T17:16:24Z")

</div>

> [@DanRathbun](#):
>
> (Hopefully, the file handle will be released when LayOut is closed.)

I never have issues when using more than one dialog object using the same template file, I only run into issues when the template file is still open in LayOut. Closing the template tab will release it, you don’t have to close the whole instance.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 16, 2026, 1:14am UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/7 "2026-03-16T01:14:58Z")

</div>

Jack, that was a brain fart on my part. (Heh, a rhyme.) I really meant …

> [@DanRathbun](#):
>
> (Hopefully, the file handle will be released when **SketchUp** is closed.)

… because this is LayOut API use from within SketchUp. (I’ve corrected the original post.)

---

<div class="post-metadata">

**Author:** ![LPera](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@LPera](https://forums.sketchup.com/u/LPera)\
**Post date:** [March 18, 2026, 11:08am UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/8 "2026-03-18T11:08:45Z")

</div>

Ohh man, thanks for this details (Dan and Napperkt) I have a similar proyect in my company that I’ve been trying to solve. Exporting the scenes into layout and putting X scenes in Y page, and not having to do it manually, and wasn’t being able to do it.

Now i can export correctly and it puts the scenes I want in the page I want! Now trying to get it to put the correct style in hidden line (in sketchup) or vectorial (in layout) havent decide what is better yet.

Again thanks a lot, been trying to do it for the past 3/4 months by my self.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [March 25, 2026, 11:09am UTC](https://forums.sketchup.com/t/extension-ruby-help-send-to-layout/345422/9 "2026-03-25T11:09:25Z")

</div>

Closed on March 25, 2026, 11:09am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
