Deleting items in model space that aren't seen inside paper space - AcadPViewport

I have a difficult (at least for me) problem. I'm using VBA inside of AutoCAD 2006. What I'm trying to accomplish is a sort of drawing
clean-up. All of the drawings my company creates need to go through this clean-up process, so I've been asked to automate it.
The end result is that any items that aren't being used inside any of the layouts should be deleted from model space.
Each drawing has at least one layout within paper space.
When I run the following code, the TypeName of the viewports are all "IAcadPViewPort2" : Dim objAcadObject As AcadObject Dim strName As String
For Each objAcadObject In ThisDrawing.PaperSpace strName = TypeName(objAcadObject) Next
The solution as I see it (please tell me if you have any better ideas) could be laid out in the following code/pseudo-code : 'Variables Dim objAcadObject As AcadObject Dim objLayout As AcadLayout
'Go to paperspace ThisDrawing.ActiveSpace = acPaperSpace
'SELECT ALL items in one of the viewports. 'This is the same as selecting all items in model space For Each objLayout In ThisDrawing.Layouts For Each objAcadObject In objLayout.Block If TypeName(objAcadObject) = "IAcadPViewport2" Then 'SELECT ALL 'Exit the loop since the selection is done Exit For End If Next Exit For Next
'UNSELECT all visible items in each viewport inside paper space For Each objLayout In ThisDrawing.Layouts For Each objAcadObject In objLayout.Block If TypeName(objAcadObject) = "IAcadPViewport2" Then 'UNSELECT all items visible in the viewport 'Same as holding down the shift key and using an X box inside the viewport 'UNSELECT 'objAcadObject.Delete End If Next Next
'Any items still selected are not being used inside paper space. 'Since they are not being used, they can be deleted, so delete them! 'DELETE
The selection and delete processes are what I can't figure out. Any help would be EXTREMELY helpful!!!!
Thanks in advance, Brian W.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.