Script to clear the Instance naming on groups and component?

Not well versed in Ruby, so i need help to write a simple ruby command to clear the Instance naming on groups and component.

SketchUp uses instance naming when using solid tools and it’s messing up some exports. Right now I’m manually going through the Outliner and deleting them.

Is there a simple ruby array script I can run that just clears this attributes for all objects in my model?

An old post here suggested

Sketchup.active_model.definitions[“Name of component”].instances.each{ |i| = “” }

But that just resulted in a

Error: #<NameError: undefined local variable or method `component”’ for main:Object
Did you mean? Complex>

:in `' SketchUp:in `eval'
  1. You have a syntax error in your code because you are using the wrong character for quotation mark: "
  2. You are trying to get component definition named to “Name of component” from the DefinitionList object and rename its instances, and there is no component (definition) named like that in your current example. The marked objects are Groups.
  3. However the Group have its definition, the name of this definition are not visible. (Internally it is Group#1, Group#2 …etc.).
  4. I guess, what you want is to reset the names of the groups to initial “Group”.

One possibility to reset the name of all groups to “Group” in a root of the model (like on the picture)

Sketchup.active_model.entities.grep(Sketchup::Group){|g| = ""}

This will do the same if you are in a model editing context, but it can be used if you are editing a group or component ant that contains a groups you want to reset the names

Sketchup.active_model.active_entities.grep(Sketchup::Group){|g| = ""}

This will reset all group names in a model hierarchy

  next unless
  d.instances.each{ |i| = "" }

Thank you! That works grate for groups. But, just to make it fool prof, is there a way to make it work for components to?

Use my last example without the 2nd line.


Life saver … Thank you!

d.instances.each{ |i| = “” }