Deleting Layouts via ObjectDBX

Discussion in 'AutoCAD' started by Michael, Feb 11, 2004.

  1. Michael

    Michael Guest

    Does anyone know if is it possible to delete layouts via Object DBX?

    Tried this quickly, it bails on the second or third layout with: "Layout
    does not exist for deletion"

    Is there another method I should be using to delete these layout's via DBX,
    or can it not be done?

    Function DeleteLayouts(FileStr As String)

    Dim dbxDoc As AXDB15Lib.AxDbDocument
    Dim Layout As AcadLayout

    Set dbxDoc =
    AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
    dbxDoc.Open FileStr

    For Each Layout In dbxDoc.Layouts
    If Layout.Name = "Model" Then
    'Do Nothing
    Else
    Layout.Delete
    End If
    Next

    dbxDoc.SaveAs (dbxDoc.Name)

    End Function
     
    Michael, Feb 11, 2004
    #1
  2. How about looping thru the layouts, with the for each, but storing them in
    an object array [ dim ArrLayout() as AcadLayout ]

    then loop thru the array, [for i= Lbound(ArrLayout) to Ubound (ArrLayout)],
    erasing each one [ ArrLayout(i).Delete ], except the ones you want to keep.
     
    Jorge Jimenez, Feb 11, 2004
    #2
  3. Michael

    Doug Broad Guest

    When deleting objects in a collection, I believe the iteration
    should be from ubound to lbound. Otherwise you have
    indexing errors and skip deleting some objects.
     
    Doug Broad, Feb 11, 2004
    #3
  4. If object reference is stored in an array, deletion could be done in any
    order.
     
    Jorge Jimenez, Feb 11, 2004
    #4
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.