# Creating Layout doc using ruby - set a variable (like auto-text) unique to each page

**URL:** <https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479>\
**Category:** Ruby API\
**Created:** [March 19, 2024, 3:45pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479 "2024-03-19T15:45:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daiku](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/daiku/32/37462_2.png) [@daiku](https://forums.sketchup.com/u/daiku)\
**Post date:** [March 19, 2024, 3:45pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479/1 "2024-03-19T15:45:16Z")

</div>

I’m creating a layout doc from Ruby in Sketchup, and I’d like to set a value for “” that I can set for each page, and then have that value appear in the title block on each page. I got it to work using AutoText (Using TYPE\_CUSTOM\_TEXT), but that changes the value for all pages. Is there a way to make an auto-text that’s unique to each page? Or some other way to set a variable that can be referenced from layout? I know I can just add a text element directly to the screen, but then the location is hard-coded, and the user can’t choose where they want it to show up on their doc.

---

<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 19, 2024, 3:52pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479/2 "2024-03-19T15:52:28Z")

</div>

> [@daiku](#):
>
> Or some other way to set a variable that can be referenced from layout?

Well LO **labels** can reference attributes in several attribute dictionaries.

Dynamic Component Dictionaries:

- `"dynamic_attributes"`

Advanced Attribute Dictionaries :

- `"SU_DefinitionSet"`
- `"SU_InstanceSet"`

---

<div class="post-metadata">

**Author:** ![daiku](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/daiku/32/37462_2.png) [@daiku](https://forums.sketchup.com/u/daiku)\
**Post date:** [March 19, 2024, 4:06pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479/3 "2024-03-19T16:06:53Z")

</div>

I’m not seeing how to reference an attribute from a label? Just auto-text. Does the label have to be attached to a sketchup component for it 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 19, 2024, 8:22pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479/4 "2024-03-19T20:22:21Z")

</div>

> [@daiku](#):
>
> Does the label have to be attached to a sketchup component for it work?

Yes, and it needs to have those dictionaries or they would not appear in the popup picklist (when choosing the label text manually.)

Doing this with the API would need a deep connection point:

- [Class: Layout::ConnectionPoint — SketchUp Ruby API Documentation](https://ruby.sketchup.com/Layout/ConnectionPoint.html)

But you may (perhaps) set the leader type to none.

Looking at the API, I do not see a way to get the attribute text from the Layout, but since you are likely running your code in SketchUp or C, you should be able to get the text from the SketchUp API.

* * *

I don’t really know what it is you are trying to achieve.

---

<div class="post-metadata">

**Author:** ![daiku](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/daiku/32/37462_2.png) [@daiku](https://forums.sketchup.com/u/daiku)\
**Post date:** [March 19, 2024, 8:42pm UTC](https://forums.sketchup.com/t/creating-layout-doc-using-ruby-set-a-variable-like-auto-text-unique-to-each-page/264479/5 "2024-03-19T20:42:27Z")

</div>

I’m creating a layout document from within sketchup, adding a page to the layout document for each component in my main model. I’d like to put the quantity in the title block of each page. I have the qty value in SU, and it would be great if I could set the value of an existing custom LO auto-text (set up in the template):

```ruby
            auto_texts = doc.auto_text_definitions
            auto_texts.each do |auto_text|
                if auto_text.tag== "<Qty>"
                    auto_text.custom_text = qty
                end
            end

```

The problem, of course, is that there is only one auto\_text for the whole doc, so the qty keeps getting overwritten.

For now, I’m doing:

```ruby
            anchor = Geom::Point2d.new(1, 1)
            text = Layout::FormattedText.new("Qty: #{qty}", anchor, Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
            doc.add_entity( text, default_layer, page )

```

So I do get the info onto the page, but the location on the page is hard-coded, and the user has to move it manually to get it where they want it (as opposed to being able to set it up in the template so it’s formatted how they like it). I could attach a custom “qty” attribute to the component in the viewport, but I still don’t see how I could get that into the title block.
