I am looking to create a plugin that will allow me to automatically populate my Layout template with all the scenes that I’ve created in my relevant 3D model.
Link to video walkthru of what I’d like to accomplish with my plugin: Layout AutoScene Plugin Request - YouTube
If you can help me write the Ruby code for this function, please respond back to me. It may take me a couple of days to check back, I’m new to this forum, but I’m very committed to making this work for myself as a big timesaver.
Thank you!
Please be aware that there are currently some limitations to the LayOut APIs.
These limitations make it difficult to easily update the viewports for a document created from a template.
(It is actually easier to replace viewports with new viewports of the same size and bounds.)
opened 06:13PM - 26 Aug 19 UTC
enhancement
Ruby API
C API
LayOut
logged
#### LayOut Ruby API Issue
**[`Layout::SketchUpModel`](http://ruby.sketchup.c… om/Layout/SketchUpModel.html) has no `#path` method**.
> We might want to name this `filepath` so as not to confuse readers with [`Layout::Path`](https://ruby.sketchup.com/Layout/Path.html) objects.
Once the object is instantiated, there is no way to get the `path` (_aka_ `filepath`) property.
If your code is creating the object, it is likely the path string is known, but if you open an existing `.layout` file, your code cannot get the path of a viewport's model.
---
**[`Layout::SketchUpModel`](http://ruby.sketchup.com/Layout/SketchUpModel.html) has no `#path=` setter method**.
> We might want to name this `filepath=` so as not to confuse readers with [`Layout::Path`](https://ruby.sketchup.com/Layout/Path.html) objects.
A coder has run into this issue where they cannot set the path for the viewport as presetup in a template, without resorting to a rigmarole of copying the template viewport's bounds and properties and recreating the viewport. _See public forum thread ..._
https://forums.sketchup.com/t/layout-ruby-and-use-of-a-template/113291
---
This is related to another issue:
* [Issue #325: Layout::SketchUpModel#bounds= method missing](https://github.com/SketchUp/api-issue-tracker/issues/325)
**EDIT**: It has been reported that viewports should be transformed using the [`Entity#transform!`](http://ruby.sketchup.com/Layout/Entity.html#transform!-instance_method) method.
opened 01:46PM - 21 Dec 20 UTC
enhancement
Ruby API
C API
LayOut
logged
parity
# 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)
Hi thank you Dan. Perhaps it has to be a SketchUp only plugin in the Ruby API? Leave no code work to be done in Layout?
Would you prefer to chat over the phone or via zoom?
LayOut does not have a live API, so if it’s Ruby then it must run from within SketchUp’s application process.
I am not sure what the solution is for this. I’ve participated in discussions about the issue, but not yet tried to solve it.
Obviously, one brute force solution would be to recreate the LayOut file 100% with code rather than try to use a template with any existing viewports.
The template can have the title block and the viewport labels but the 2D locations of viewports would need to be known (somehow) to the extension.
LayOut API objects can not yet have attribute dictionaries attached to them, which would otherwise be a good way to “mark” rectangles with the name of a scene to be replaced with a model viewport.
Thinking … perhaps groups with a rectangle and a text object inside naming the scene with a “Viewport:” prefix?
The code could search for these groups and replace them with a viewport using the child rectangles bounds and set the scene per the given text.
Issues arise later if needing to update the viewports and you’ve manually added stuff to the LayOut document such as notes, dimensions, etc.
There is an open issue, where removing a model viewport does not seem to work.
opened 01:35PM - 21 Dec 20 UTC
bug
Ruby API
SketchUp
LayOut
logged
# Bug
1. Create a SketchUp Document with a Scene with some Entities visible
… 2. Use the API to create a Layout Document and insert a Layout::SketchUpModel referencing the aforementioned Scene
3. Save the Layout Document and inspect it. (Verify the scene is embedded correctly, perform a PDF Export)
4. Create another Scene viewing another region in the *original* SketchUp Document
5. Move at least one Entity from the first to the second Scene
6. Use the API to open the existing Layout Document.
7. Remove the Layout::SketchUpModel entity
8. Add two new Layout::SketchUpModels for each scene (The old one, and the new one)
9. Save the Layout Document and inspect it. (Verify both new scenes in Layout document, perform a PDF Export)
The Layout file shows both SketchUpModel Entities as they are now in the SketchUp Document.
However, the PDF Export of the modified Layout Document is now corrupted.
The first Scene contains the Entities from before, the new Scene does not contain anything.
Chose the first or second SketchUpModel and right click on "Update Model Reference"
The "corruption" is now visible in Layout itself.
# Reproduce with:
The Setup:
```
# Create some entity at origin
circle_entities = Sketchup.active_model.entities.add_circle(Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1), 5, 32)
circle = Sketchup.active_model.entities.add_group(circle_entities)
# Prepare view for scene (zoomed in on entity at origin)
Sketchup.active_model.active_view.zoom_extents
# Create first scene (view on entity at origin)
scene_a = Sketchup.active_model.pages.add("First Page")
# Save SketchUp Document
Sketchup.active_model.save("/tmp/test.skp")
# Create Layout Document
lo_document = Layout::Document.new()
# Create Layout::SketchUpModel
lo_su_bounds = Geom::Bounds2d.new(1, 1, 3, 3)
lo_su_model = Layout::SketchUpModel.new("/tmp/test.skp", lo_su_bounds)
lo_su_model.current_scene = 1
lo_su_model.render if lo_su_model.render_needed?
# Add SketchUpModel Entity to Layout Document
lo_document.add_entity(lo_su_model, lo_document.layers.first, lo_document.pages.first)
# Save Layout Document
lo_document.save("/tmp/test.layout")
# Export a PDF
lo_document.export("/tmp/test_first.pdf")
#
# Close Sketchup
#
```
At this point you should have the files; test.skp, test.layout and test_first.pdf
Inspecting test.layout and test_first.pdf shows a circle on the first and single page
Now for the Bug:
(Don't forget to close the layout file before proceeding)
```
# Open SketchUp Document
Sketchup.open_file("/tmp/test.skp")
# Reference first scene
scene_a = Sketchup.active_model.pages.first
# Reference original circle
circle = Sketchup.active_model.entities.first
# Move circle to the "right"
circle.move!(Geom::Vector3d.new(15, 0, 0))
# Prepare view for second scene
Sketchup.active_model.active_view.zoom_extents
# Create second scene
scene_b = Sketchup.active_model.pages.add("Second Page")
# Create another entity at origin for first scene
triangle_entities = Sketchup.active_model.entities.add_circle(Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1), 5, 2)
triangle = Sketchup.active_model.entities.add_circle(Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1), 5, 2)
# Save SketchUp Document again
Sketchup.active_model.save()
# Open Layout Document again
lo_document = Layout::Document.open("/tmp/test.layout")
# Reference first Page on Layout Document
lo_page_a = lo_document.pages.first
# Reference existing Layout::SketchUpModel
original_su_model = lo_page_a.entities.first
# Remark: At this point an update_model_reference would be great
# Instead: Remove original Layout::SketchUpModel
lo_document.remove_entity(original_su_model)
# Create second page on Layout Document
lo_page_b = lo_document.pages.add("Second Page")
# Create Layout::SketchUpModel for first scene
lo_su_bounds = Geom::Bounds2d.new(1, 1, 3, 3)
lo_su_model_a = Layout::SketchUpModel.new("/tmp/test.skp", lo_su_bounds)
lo_su_model_a.current_scene = 1
lo_su_model_a.render if lo_su_model_a.render_needed?
# Add first SketchUpModel Entity to first page on Layout Document
lo_document.add_entity(lo_su_model_a, lo_document.layers.first, lo_page_a)
# Create Layout::SketchUpModel for second scene
lo_su_model_b = Layout::SketchUpModel.new("/tmp/test.skp", lo_su_bounds)
lo_su_model_b.current_scene = 2
lo_su_model_b.render if lo_su_model_b.render_needed?
# Add second SketchUpModel Entity to second page on Layout Document
lo_document.add_entity(lo_su_model_b, lo_document.layers.first, lo_page_b)
# Save Layout Document
lo_document.save("/tmp/test.layout")
# Export a PDF
lo_document.export("/tmp/test_second.pdf")
```
Now we should have another file called test_second.pdf
Open test.layout
Notice a triangle on the first and a circle on the second page
This is as expected
Open test_second.pdf
Notice a circle on the first and nothing on the second page
This is faulty
# Suspicion
`Layout::Document.remove_entity(...)`
and
`Layout::Layers.delete_entities(..., delete_entities=true)`
do not remove the internaly stored SketchUp Document.
Creating a new SketchUpModel Entity in the Layout Document uses the cached SketchUp Document instead of the updated one.