# Replace components in component browser tray

**URL:** <https://forums.sketchup.com/t/replace-components-in-component-browser-tray/171952>\
**Category:** Ruby API\
**Created:** [August 5, 2021, 3:38pm UTC](https://forums.sketchup.com/t/replace-components-in-component-browser-tray/171952 "2021-08-05T15:38:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [August 5, 2021, 6:58pm UTC](https://forums.sketchup.com/t/replace-components-in-component-browser-tray/171952/2 "2021-08-05T18:58:42Z")

</div>

> [@KQV](#):
>
> Firstly, it can only replace components in current Model and can not replace components in component browser tray.

I’m not sure if you want to modify the “Component Replacer” or you already tried to write your own.  
Would be the best if you can provide your code what is failed, than someone may take a look on it…  
\_\_  
Perhaps you can check this methods (including but not limited to)

The [#load](https://ruby.sketchup.com/Sketchup/DefinitionList.html#load-instance_method) method is used to load a component from a file.

The [#add](https://ruby.sketchup.com/Sketchup/DefinitionList.html#add-instance_method) method is used to add a new component definition to the definition list with the given name.

The [#remove](https://ruby.sketchup.com/Sketchup/DefinitionList.html#remove-instance_method) method is used to remove a component definition from the definition list with the given component definition. This will remove all instances of the definition.

The [#purge\_unused](https://ruby.sketchup.com/Sketchup/DefinitionList.html#purge_unused-instance_method) method is used to remove the unused component definitions.

> [@KQV](#):
>
> Secondly, I want to perform Reraw DC in order that DCs are recalculated after being replaced.

> [@Method to ask a dynamic component instance to recalc itself?](https://forums.sketchup.com/t/method-to-ask-a-dynamic-component-instance-to-recalc-itself/13905/6):
>
> Yes, true, you are correct. (1) It still exists. (2) It itself is poor practice, and could have been a class variable reference (implemented in a singleton manner.) It could have been exposed via a class constant or a class getter method. (3) As I said above, It might not exist in future versions, if they re-implement it’s reference per (2). So, you’ll need to do a object search and hold a local reference inside your module, to the same singleton object that $dc\_observers is also referenci…

---

_[View the full topic](https://forums.sketchup.com/t/replace-components-in-component-browser-tray/171952)._
