Macro to find similar labeled parts and delete them all

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
CoderMusashi
Posts: 92
Joined: Mon Nov 19, 2018 8:26 pm

Macro to find similar labeled parts and delete them all

Post by CoderMusashi »

I deal with large Die Assemblies on a daily basis. Some of the files are rather big and take time to load. I don't need all the stuff in the die assembly so I delete what I don't want and save the file so the next time I load it, the file loads faster. Deleting every 1/2-13 bolt or dowel one by one or even using a selection box can be a lengthy process. So I created this macro to seek out similar labeled parts and delete them all in one go. It searches by label starts with. So I will select a bolt for example then look at what it is labeled. Say for example 10mm is the label. I run the script and type in 10mm and it deletes all parts with a label that starts with 10 mm. I hope someone else finds this as beneficial as I have.
Attachments
seekANDdestroy.FCMacro
(592 Bytes) Downloaded 30 times
Last edited by CoderMusashi on Mon Sep 09, 2019 10:07 pm, edited 1 time in total.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Macro to seek and destroy

Post by TheMarkster »

Consider adding

Code: Select all

doc.openTransaction("seek and destroy")
#your code to delete the objects here
doc.commitTransaction()
This would add it to the undo stack, enabling the user to undo the operation (Ctrl+Z) if something was accidentally deleted.
freedman
Veteran
Posts: 3474
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Macro to seek and destroy

Post by freedman »

CoderMusashi , you could change the wording of the subject to get better search parameters, "part text search", something like that. "Seek" might be a good word.
Post Reply