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

Discussion in 'AutoCAD' started by Brian W., Nov 13, 2007.

  1. Brian W.

    Brian W. Guest

    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.
     
    Brian W., Nov 13, 2007
    #1
  2. Brian W.

    strawberry Guest

    I'm sure I replied to this already - but I can't see my post.

    I'd simply wblock the contents of the viewport to a new file - and
    then insert the old view port into the new file and save that back
    over the old file.
     
    strawberry, Nov 17, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.