Delete Multiple Components from the list at one time?

Besides Purging, is there a way to delete multiple components at a time from the component list?

The issue I’m having is that when I purge all, SU crashes.

I suspect I have one bad component in the mix. In the past I’ve taken the time to one by one right click on the component and delete until I find the one that crashes SU.

But is seems silly that although I can select multiple components at once, I am not able to right click and select delete. If I could, this would allow me to find the bad component faster by first trying to delete top half of the list, if it crashes, I know the one I’m looking for is somewhere there. from there I can reopen and try alphabetical groups “a” thru “d”, “e” thru “k” … until I get a crash again, and so on… With this method after about 5 to 10 attempts I should be able to narrow down and identify the bad apple. Without that ability, I’m forced to delete one by one… and in large models a few hundred components, this can take way too long.

Have you tried purging only components?

Hey Dave,

I tried purging just the components and I still get a crash.

I can purge everything else with no problems.

It seems I have one bad component in my model, I’ll eventually find it, but it would be nice to be able to delete 5, 10, 20… components at a time so it would be faster in finding the corrupt component. This seems like a relatively easy option to add in a future update. :crossed_fingers:

It’s a relatively simple Ruby script…
But first you need to set up a ‘pattern’ to match in the components’ names…
So let’s say the ‘bad’ component definitions start with the text ‘Aardvark’…
Here’s some [untested] sample code…

model = Sketchup.active_model
model.start_operation('compos_togo', true) # for possible undo
defns = model.definitions
togos = []
defns.each{|e| togos << e if e.name =~ /^Aardvark/ }
# there are many pattern matching possibilities...
togos.each{|e| defns.remove(e) }
model.commit_operation # allowing an undo
2 Likes

Thanks TIG!

I’ll definitely give that a try. Can you do wild cards similar to windows command prompt?

Example, " a* " for any entity starting with the letter " a " or " *box * " for any entity that has the word " box " within it?

Use regex…
For starting with a
\ba\w*\b
For word “box”
\wbox\w

1 Like

Thanks guys for the help.

The Script works great in deleting batches of components.

Turns out I still have difficulty finding the bad apple though. My theory for deleting letter groups at a time until I find a letter group that crashes, sort of worked, but then when I reopened and tried to delete the letter group one by one, no crash was produced.

In thinking of another approach, I noticed this script deletes components regardless if they are being used in the scene or not. Is there a way to modify this script to only delete components that are not used? So in the end I can purge letter groups and see if that helps me find the corrupt component.

Thanks again! :pray:

Try to modify this line. (not tested as I’m not at the computer)

defns.each{|e| togos << e if (e.name =~ /^Aardvark/ && e.count_used_instances == 0)}
1 Like

Thank you, @rtches and @TIG!

In the end the combination of your code managed to purge all unused components in one go without crashing.

model = Sketchup.active_model
model.start_operation('compos_togo', true) # for possible undo
defns = model.definitions
togos = []
defns.each{|e| togos << e if (e.name =~ /^*/ && e.count_used_instances == 0)}
# there are many pattern matching possibilities...
togos.each{|e| defns.remove(e) }
model.commit_operation # allowing an undo

Not sure why the native purge feature crashes on this model, but I am grateful for your ruby script knowledge and will keep this code handy the next time I run into this glitch. I was finally able to clear out old components bringing my model from 93MB to 76MB. :slight_smile:

Note after the Ruby Script Purge Components, the native Window → Model Info → Statistics → Purge Unused works without crashing!

Thanks again!
Chris

1 Like