# Component Instance renaming doesn't work

**URL:** <https://forums.sketchup.com/t/component-instance-renaming-doesnt-work/263997>\
**Category:** Ruby API\
**Created:** [March 15, 2024, 9:59pm UTC](https://forums.sketchup.com/t/component-instance-renaming-doesnt-work/263997 "2024-03-15T21:59:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![milmandre](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/milmandre/32/76145_2.png) [@milmandre](https://forums.sketchup.com/u/milmandre)\
**Post date:** [March 15, 2024, 9:59pm UTC](https://forums.sketchup.com/t/component-instance-renaming-doesnt-work/263997/1 "2024-03-15T21:59:02Z")

</div>

Hi all,

That makes a really long time that I wasn’t able to work on SU Plugins. Now I’m back and takes a real plaisure to work on SU again. Now I’m on the 2023 version and I came from 2017.

Now I experiencing Components problems. Renaming Component Definition works perfectly but renaming Instances doesn’t work.

The name command doesn’t generates errors but the result isn’t applied and the Instance doesn’t get a name applied.

Is there any process to follow to get the Instance name applied?

Thanks for your answers 😉

---

<div class="post-metadata">

**Author:** ![KScher](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/kscher/32/41084_2.png) [@KScher](https://forums.sketchup.com/u/KScher)\
**Post date:** [March 15, 2024, 11:07pm UTC](https://forums.sketchup.com/t/component-instance-renaming-doesnt-work/263997/2 "2024-03-15T23:07:09Z")

</div>

> [@milmandre](#):
>
> renaming Instances doesn’t work

Everything works.

```auto
module RenameComponent
  def self.rename_instance
    model = Sketchup.active_model
    selection = model.selection
    first_selected = selection[0]

    if first_selected.is_a?(Sketchup::ComponentInstance) || first_selected.is_a?(Sketchup::Group)
      prompts = ["New name:"]
      defaults = [first_selected.name]
      input = UI.inputbox(prompts, defaults, "Rename Component")
      new_name = input[0]

      unless new_name.nil? || new_name.strip.empty?
        model.start_operation('Rename Component', true)

        # Rename the component or group
        first_selected.name = new_name

        model.commit_operation
        UI.messagebox("Component successfully renamed to '#{new_name}'.")
			end
    end
  end

end # mod

RenameComponent::rename_instance

```

---

<div class="post-metadata">

**Author:** ![milmandre](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/milmandre/32/76145_2.png) [@milmandre](https://forums.sketchup.com/u/milmandre)\
**Post date:** [March 20, 2024, 4:50pm UTC](https://forums.sketchup.com/t/component-instance-renaming-doesnt-work/263997/3 "2024-03-20T16:50:22Z")

</div>

Thanks for your answer.

I must be more explicit, sometime it works but sometimes not… Is there any environement codition that have impact on renaming instances ?

Look at theses image which illustrate the code result. Someof them are renamed and other not:

**Instance Name not applied**

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/0/e/0ee9795531da81a58c8d3d1f593babab623096c8.png)

**Instance Name applied**

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/e/2/e232c910c8b2cd7735e86c824976935bcfd1f100.png)

If you want to make some analyze/taest you can see the developpement on [GitHub - jeremiegalante/Positive-Habitat: Plugin SketchUp RBZ - Positive Habitat](https://github.com/jeremiegalante/Positive-Habitat)

Any ideas ?
