Explode Tag Folder question

I have a file with many nested tag folders. I want to ‘explode’ all of them so that no folders remain. Right now, I have to right-click each tag folder and select Explode Tag Folder one by one. Since I have around 80 folders (some inside others), this is too time-consuming. Is there a way to explode multiple tag folders at once, including those inside other folders?

I did try to use ChatGPT to write a ruby script to do this but i kept getting an message telling me, "No Tag Folder API available in this SketchUp build.

I’m using the very latest build of Pro. Thanks for any help.

Well, this is a kind of AI. (Artificial Idiot) :wink:

Certainly there are a classes in Ruby API to handle tag folders.
Class: Sketchup::Layer
Class: Sketchup::Layers
Class: Sketchup::LayerFolder

Here is one possible example snippet to Explode/remove all tag folders:
(I tested it just for only one specific tag folder structure case… which I created randomly)

def all_folders(folders = [], root_folder = Sketchup.active_model.layers)
  root_folder.each_folder do |folder|
    folders<<folder
    all_folders(folders, folder)
  end
  folders
end

def my_remove_tagfolders
  folders = all_folders
  return if folders.empty?
  root = Sketchup.active_model.layers
  Sketchup.active_model.start_operation("Remove tagfolders", true)
  folders.to_a.each{|f|
    f.folder ? f.folder.remove_folder(f) : root.remove_folder(f)
  }
  Sketchup.active_model.commit_operation
end
my_remove_tagfolders
1 Like

This also seem to work well:

def remove_all_tag_folders
  # Reference the active model:
  model = Sketchup.active_model
  model.start_operation("Remove tag folders", true)
    #
    # Get an array of all the layer tags:
    tags = model.layers.to_a
    # Reject the "Untagged" tag:
    tags.reject! { |tag| tag.name == "Layer0" }
    # Clear all folder assignments:
    tags.each { |tag| tag.folder= nil }
    # Remove all tag folders:
    model.layers.purge_unused_folders
    #
  model.commit_operation
end
3 Likes

You did it. You actually did exactly what i was wanting SU to be able to do. Thank you!
I respect all the developers out there making SU better. I have no mind for coding so I thought i’d take ChatGPT for a spin. Obviously there is no replacement for knowing what you’re actually doing. :slight_smile:

I made it so your code is in a script that shows up in the Extensions menu so i can use it whenever I run into this issue again.
ExplodeTagFolders.rb (1.2 KB)

I dropped it in C:\Users\YourNameHere\AppData\Roaming\SketchUp\SketchUp 2025\SketchUp\Plugins

Works like a charm!!!
Again, thanks so much