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

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.

Well LO labels can reference attributes in several attribute dictionaries.

Dynamic Component Dictionaries:

  • "dynamic_attributes"

Advanced Attribute Dictionaries :

  • "SU_DefinitionSet"
  • "SU_InstanceSet"

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?

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:

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.

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):

            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:

            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.