Batch rename Group Instance

I have a project of 350 odd groups.
I’m trying to find the odd group(s) that has a strange length.
I can only use instance to name the group to find the strange length.
Is there an extension to batch rename all groups instances?
Like 1,2,3,4…
Just want a quick n dirty .rd to batch rename all group instances.

Thanks in advance.

You wanted to say .rb. don’t you ? :wink:

:bulb: Something like this?
However it is not an .rb, just a snippet.
Copy paste the code snippet below to Ruby console and hit enter:
All groups, including nested will be renamed.
You can Undo it!
No warranties! Use your own risk!

module Dezmo
module GroupRenamer
  extend self
  
  def recur_group_rename(ents)
    ents.each{|e|
      case e
      when Sketchup::Group
        @num += 1
        e.make_unique
        e.name = @num.to_s
        recur_group_rename(e.definition.entities)
      when Sketchup::ComponentInstance
        if !@defs.include?(e.definition)
          recur_group_rename(e.definition.entities)
          @defs<<e.definition
        end
      end
    }
  end
  
  def grouprename
    model = Sketchup.active_model
    ents = model.entities
    @num = 0
    @defs = []
    model.start_operation("Rename groups to numbers", true)
    recur_group_rename(ents)
    model.commit_operation
    "#{@num} Groups renamed"
  end
end
end
Dezmo::GroupRenamer.grouprename

grouprename

1 Like

This looks very usefull, but is there a way that it only renames groups that are not named yet?

module Dezmo
module GroupRenamerB
  extend self
  
  def recur_group_rename(ents)
    ents.each{|e|
      case e
      when Sketchup::Group
        if e.name == ""
          @num += 1
          e.make_unique
          e.name = @num.to_s
        end
        recur_group_rename(e.definition.entities)
      when Sketchup::ComponentInstance
        if !@defs.include?(e.definition)
          recur_group_rename(e.definition.entities)
          @defs<<e.definition
        end
      end
    }
  end
  
  def grouprename
    model = Sketchup.active_model
    ents = model.entities
    @num = 0
    @defs = []
    model.start_operation("Rename groups to numbers if no name", true)
    recur_group_rename(ents)
    model.commit_operation
    "#{@num} Groups renamed"
  end
end
end
Dezmo::GroupRenamerB.grouprename
1 Like

thank you very much

1 Like

Absolute Champion!
This issue was starting to annoy me again.
Saved a lot of agro.
Many thanks!