# How to add built-in Dynamic Component Attributes?

**URL:** <https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230>\
**Category:** Ruby API\
**Tags:** components\
**Created:** [December 4, 2024, 2:44pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230 "2024-12-04T14:44:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://forums.sketchup.com/u/qube)\
**Post date:** [December 4, 2024, 2:44pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/1 "2024-12-04T14:44:52Z")

</div>

I have a question about programmatically adding built-in Component Attributes (like ‘Position: X’, or ‘Size: LenX’, or ‘Behaviours: Hidden’ via a Ruby script.

I am able to programmatically create a dynamic component and to programmatically create Custom Attributes within that component but I’ve been unable to find a way to programmatically add any of the built-in Component Attributes to the component.

---

<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:** [December 4, 2024, 3:33pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/2 "2024-12-04T15:33:40Z")

</div>

See my recent post(s) …

- [Adding dynamic attributes to select their values in LayOut labels - #2 by DanRathbun](https://forums.sketchup.com/t/adding-dynamic-attributes-to-select-their-values-in-layout-labels/296630/2)

- [Adding dynamic attributes to select their values in LayOut labels - #3 by DanRathbun](https://forums.sketchup.com/t/adding-dynamic-attributes-to-select-their-values-in-layout-labels/296630/3)

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [December 4, 2024, 4:20pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/3 "2024-12-04T16:20:41Z")

</div>

Moved to the appropriate category and renamed based on Dan’s suggestion.

---

<div class="post-metadata">

**Author:** ![ryan.moore](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/ryan.moore/32/106089_2.png) [@ryan.moore](https://forums.sketchup.com/u/ryan.moore)\
**Post date:** [December 4, 2024, 4:39pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/4 "2024-12-04T16:39:17Z")

</div>

As Dan once told me, there is a lot more happening in a DC than appears in the dialog. You can see the hidden attributes preceded by an \_underscore with the Attribute Helper extension (by SketchUp) or the Attribute Inspector extension (by Aerilius). All of these hidden attributes need to be in place for an attribute to work properly.

Here is a working snippet for adding LenX:

EDIT: Removed an un necessary line setting LenX, setting the \_lenx\_formula also sets LenX.

```ruby
# works on bulk selections.

Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).each do |dc|
  dc.definition.set_attribute( 'dynamic_attributes','_lenx_label','LenX')
  dc.definition.set_attribute( 'dynamic_attributes','_lenx_formula', '24')
  $dc_observers.get_latest_class.redraw_with_undo(dc)
end

```

---

<div class="post-metadata">

**Author:** ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://forums.sketchup.com/u/qube)\
**Post date:** [December 4, 2024, 5:45pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/5 "2024-12-04T17:45:42Z")

</div>

Much obliged Dan. I’ll absolutely review your posts.

In the meantime, I came across this post and got myself started, using one of the snippets in the post in adding what I call a ‘built-in’ attribute (as opposed to Custom) ‘Size: LenX’

[https://forums.sketchup.com/t/manage-different-access-to-dynamic-attributes-in-ruby/62204/3](https://forums.sketchup.com/t/manage-different-access-to-dynamic-attributes-in-ruby/62204/3)

---

<div class="post-metadata">

**Author:** ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://forums.sketchup.com/u/qube)\
**Post date:** [December 4, 2024, 5:46pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/6 "2024-12-04T17:46:19Z")

</div>

Thx for re-categorizing Dezmo.

---

<div class="post-metadata">

**Author:** ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://forums.sketchup.com/u/qube)\
**Post date:** [December 4, 2024, 5:56pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/7 "2024-12-04T17:56:02Z")

</div>

Thanks a lot Ryan.

Your snippet works perfectly and is essentially a tidier version of the one I stumbled on (referenced in my reply to Dan above) after posting my question.

By the way, I checked out what I assume is your business site:

[https://buildvitruvian.ca](https://buildvitruvian.ca)

… beautiful work and feel (I’m a hobbyist woodworker so your work connects with me).

Many thanks.

---

<div class="post-metadata">

**Author:** ![ryan.moore](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/ryan.moore/32/106089_2.png) [@ryan.moore](https://forums.sketchup.com/u/ryan.moore)\
**Post date:** [December 4, 2024, 6:27pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/8 "2024-12-04T18:27:28Z")

</div>

You are very welcome and thanks for the praise. 😁

---

<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:** [December 4, 2024, 8:04pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/9 "2024-12-04T20:04:10Z")

</div>

> [@qube](#):
>
> Your snippet works perfectly and is essentially a **tidier** version of the one I stumbled on (referenced in my reply to Dan above) after posting my question.

It can be tidier as there are defaults. For example if you do not explicitly set an individual attribute units (as in the non-tidier example you linked) then the attribute will default to using the component’s global units which are set in `_lengthunits` (which can be `"INCHES"` or `"CENTIMETERS"`.)

---

<div class="post-metadata">

**Author:** ![qube](https://avatars.discourse-cdn.com/v4/letter/q/ea666f/32.png) [@qube](https://forums.sketchup.com/u/qube)\
**Post date:** [December 4, 2024, 8:44pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/10 "2024-12-04T20:44:29Z")

</div>

Thanks again Dan.

I’m planning to build a suite of modular scripts to automate the modelling of more complex assemblies of dynamic components.

I’ve built those types of nested DCs manually over the last few years, importing models into models, and tweaking/upgrading formula references, etc., expecting at some point to dive into ruby to automate what was obviously a lot of repetitious work building components with similar attributes.

Found snorkel and diving in.

---

<div class="post-metadata">

**Author:** ![JackyM](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@JackyM](https://forums.sketchup.com/u/JackyM)\
**Post date:** [August 29, 2025, 3:58pm UTC](https://forums.sketchup.com/t/how-to-add-built-in-dynamic-component-attributes/302230/11 "2025-08-29T15:58:29Z")

</div>

Closed on August 29, 2025, 3:58pm UTC


