Identifying unused components

Contrary to my earlier post, the script below isn’t a one-liner - I spread it out a bit to simplify adding more functionality later since it seems likely that more is needed than just identifying them. If loaded in the Ruby Console, it will list the names of all the components that are currently unused.

I must note that in the discussion so far there is some confusion about “unused”. To me, “unused” means that there are no instances of the component currently in the model, just a definition lingering in the components collection. A definition is technically capable of having a tag assigned, but so far as I know, there is no way to do this via the GUI, so you can’t identify definitions to be preserved by tagging them in the GUI. You can tag instances, but there are none! A definition also has no associated transformation, that is, it has no location or orientation in the model. That is a property of an instance, and an “unused” component has no instances.

The workflow @kamambers describes is for when you want to remove instances from the model but preserve them for later reinsertion. The definition is necessarily carried along with instances when you copy them to another model because they can’t exist without the definition.

module SLBPlugins
  module UnusedComponents
    def self.find_unused
      unused = []
      Sketchup.active_model.definitions.each do |defn|
        next if defn.image? || defn.group?
        unused << defn if defn.instances.count == 0
      end
      unused
    end

    def self.list_unused
      unused = find_unused
      if unused.empty?
        puts "all components used"
      else
        puts unused.map {|defn| defn.name}.join("\n")
      end
    end
  end
end
SLBPlugins::UnusedComponents.list_unused
1 Like

Don’t stop asking. A working search function within the in model components window is a must! It should be a priority FR IMHO. Also a method to adjust list order (alphabetical, number of instances, file size) of component in model. Select Unused would be a nice feature that I would use as well.

2 Likes

OK all, thanks for the input! I’m really digging into the component browser, but getting increasingly confused. I’m going to assume for now that I’m doing this wrong, but it really seems like a bug. I got the FlexTools ComponentFinder which seemed at first glance to be very helpful–at least I could make my components big enough to see! But working this new extension revealed to me that I simply don’t understand what is happening when I try to save a local collection. I have the browser showing components In Model. The browser shows 114 items (not expanded). Next I select Save As A Local Collection from the Details arrow. But when I check what I saved, there are only 45 components out of the 114 in model. It’s plain as day–for example my “bed” is clearly there in my components, it is being used in the model, but it–and 69 other components–will not save to a local folder. Either I’m completely misunderstanding how this component browser is supposed to work, or it simply doesn’t work. What am I missing?

I’m with you on that. I have done the same in requesting alternate or better ways of approaching a task from tech support many times.
Often times methods of doing things are designed by programmers that don’t use the program daily or for the tasks you are using it for.
In the company I worked for, until the lock-down, we used an inventory/estimating program heavily and we made so many suggestions for improvements and fixes they finally started soliciting suggestions from us and met with our IT guy regularly to review our list of suggestions.
The program is supposed to make our job easier, not force us to to do something in a way that forces us to do something in a way that forces us to do it in a less productive way.

That being said I find SketchUp to be a much easier way to accomplish what I want than most other tools.

Yes, this issue is common to many users and has been reported several times. Today, thanks to TIG, I was able to solve this problem. But I see that you have already found my topic. Good luck!

I feel better knowing I’m not crazy (not completely anyway). We live in a world where we’re all beta testers all the time. My biggest fear was that I simply didn’t get it (which happens), but in this case, there seem to be bigger problems complicating my initial goal of identifying unused components. How long have these browser issues been going on?

I don’t remember it being any different. Too long already!