Running this macro will clean up all Part Bodies in the current model. This is a VBA format, but could possibly be rewritten as a CATScript. Error handling has been kept to a minimum, but can be added as required by the user. There is no user selection required.

Application summary: (Module "DelAllUnusedBodies")

Nested Loop
1) Count all Bodies in the current part and return the item index
2) Use index to establish loop (for all Bodies in current part)
3) Set current Body to index item
4) Count all HybridShapes in current PartBody and return index
5) Use HybridShapes index to establish loop (for all HybridShapes in current PartBody)
6) Test all HybridShapes for inactivity - if "True", add to collection
7) End HybridShapes loop; End Current Bodyloop.
/ Nested Loop

8) Count items in Collection and return the item index
9) Use index to establish loop (for all items in collection)
10) Delete all items in collection; end loop
11) Count all remaining Bodies in current Part and return the item index
12) Use remaining Bodies index to establish loop (for all remaining Bodies)
13) Test all remaining Bodies for HybridShapes count
14) Add all Bodies with no HybridShapes to collection; end loop
15) Count all items in collection and return the item index
16) Use index to establish loop (for all items in collection)
17) Delete all items in collection; end loop

The module titled "DelUnusedBodies" is similar to "DelAllUnusedBodies", except that it omits a count of all Bodies in the current part, and searches only for inactive operations within "PartBody". This may be modified, but "DelAllUnusedBodies" will work for either situation, and is the preferred method.


To download, right click the link below, and select "Save Link As...."

Delete Unused Bodies VBA