# Component attributes using Ruby

**URL:** <https://forums.sketchup.com/t/component-attributes-using-ruby/170429>\
**Category:** Ruby API\
**Created:** [July 17, 2021, 12:46pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429 "2021-07-17T12:46:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bikalbaral13](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bikalbaral13](https://forums.sketchup.com/u/bikalbaral13)\
**Post date:** [July 17, 2021, 12:46pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/1 "2021-07-17T12:46:51Z")

</div>

How to add attributes in a component using Ruby. Though I added in component but it is not updated

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [July 17, 2021, 1:17pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/2 "2021-07-17T13:17:13Z")

</div>

Are you trying to add an attribute for your own use, or for a Dynamic Component? They both use the attribute dictionary properties of objects, though the latter requires specific dictionaries and formats.

---

<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:** [July 17, 2021, 1:17pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/3 "2021-07-17T13:17:18Z")

</div>

> [@Why DC can't access attribute?](https://forums.sketchup.com/t/why-dc-cant-access-attribute/162804/2):
>
> 1. Your code is not defensive. Check that your selected entity is non-false (ie, not nil) and actually has the proper dictionary, before trying to get an attribute. Beware of using attribute\_dictionaries['dynamic\_attributes'] because it can return nil if the object’s [Sketchup::AttributeDictionaries](https://ruby.sketchup.com/Sketchup/AttributeDictionaries.html) collection is empty. So att\_dics['report'] could be the same as: nil['report'], which will cause error: Error: #\<NoMethodError: undefined method '[]' for nil:NilClass\> 2. You don’t understa…

---

<div class="post-metadata">

**Author:** ![bikalbaral13](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bikalbaral13](https://forums.sketchup.com/u/bikalbaral13)\
**Post date:** [July 17, 2021, 1:30pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/4 "2021-07-17T13:30:31Z")

</div>

group\_brickbats= entities.add\_group  
group\_brickbats.name=“group\_brickbats”  
circle\_=group\_brickbats.entities.add\_circle([0.0,-60.0,0.0],[0.0,0.0,1.0],26.716535433070867,50)  
face\_ =group\_brickbats.entities.add\_face(circle\_)  
face\_.pushpull(-2)  
comp=group\_brickbats.to\_component()  
comp.set\_attribute ‘something1’ ,‘something2’, ‘100’

### here everything works fine while running but when going to model component attributes : the attribute is not added…###

---

<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:** [July 17, 2021, 1:50pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/5 "2021-07-17T13:50:09Z")

</div>

Would you please edit your post according to:  
[how-to-post-correctly-formatted-and-colorized-code-on-the-forum](https://forums.sketchup.com/t/how-to-post-correctly-formatted-and-colorized-code-on-the-forum/46189)

---

<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:** [July 17, 2021, 1:55pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/6 "2021-07-17T13:55:40Z")

</div>

> [@bikalbaral13](#):
>
> when going to model component attributes

Can you please explain it how and what are you checking?

when you use:

```auto
comp=group_brickbats.to_component()

```

…the `comp` variable is a [componentInstance](https://ruby.sketchup.com/Sketchup/ComponentInstance.html). Therefore you set the attributes of that instance.  
Are you checking the instance or its definition ?

---

<div class="post-metadata">

**Author:** ![bikalbaral13](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@bikalbaral13](https://forums.sketchup.com/u/bikalbaral13)\
**Post date:** [July 17, 2021, 2:12pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/7 "2021-07-17T14:12:58Z")

</div>

I meant to say I run the code , then a cylinder is drawn successfully , I right clicked on the compoennt ,went to dynamic components\> component attributes , but the attributes have not been updated

---

<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:** [July 17, 2021, 3:07pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/8 "2021-07-17T15:07:15Z")

</div>

Setting an attribute does not mean that it will be a Dynamic Component.

[Dynamic Components](https://extensions.sketchup.com/extension/7d49b82a-1e6a-40ae-ab88-82fba11c4891/dynamic-components) is a “similar” extension than the other user created one. It is using its special `dynamic_attributes`. So unless you set that you will not see in the Dynamic Components extension user interface.

Dealing with Dynamic Components is something different…Please check again my first post in this topic.

PS: Since the Dynamic Components code is not public you have to know (examine) about its attributes before you can deal with them.

---

<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:** [July 17, 2021, 5:03pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/9 "2021-07-17T17:03:19Z")

</div>

> [@dezmo](#):
>
> Setting an attribute does not mean that it will be a Dynamic Component.

Yes, but we can understand Bikal’s confusion as the Dynamic Component dialogs are captioned simply “ **Component Options** ” and “ **Component Attributes** ”.

---

<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:** [July 17, 2021, 5:33pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/10 "2021-07-17T17:33:03Z")

</div>

Sure. I tried to explain …  
( Do you think “my style” was offensive or annoying…? It was not intentional… 😊)

---

<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:** [July 17, 2021, 11:43pm UTC](https://forums.sketchup.com/t/component-attributes-using-ruby/170429/11 "2021-07-17T23:43:04Z")

</div>

> [@dezmo](#):
>
> Do you think “my style” was offensive or annoying…?

No. Simple, straightforward, and matter of fact.
