Component Instance renaming doesn't work

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

Everything works.

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

1 Like

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

Instance Name applied

If you want to make some analyze/taest you can see the developpement on GitHub - jeremiegalante/Positive-Habitat: Plugin SketchUp RBZ - Positive Habitat

Any ideas ?