Detach an unloaded xref

Discussion in 'AutoCAD' started by AKS, Nov 11, 2004.

  1. AKS

    AKS Guest

    How does one detect an unloaded xref in VBA?

    tia, aks
     
    AKS, Nov 11, 2004
    #1
  2. An unloaded XREF has a blank block definition , that is, it has a block
    definition with no entities

    So checking the block definition for each entity that is an
    "acadexternalreference" will let you detect if it's unloaded or not.
     
    Jorge Jimenez, Nov 12, 2004
    #2
  3. AKS

    AKS Guest

    Thanks Jorge. I'm assuming the .Count for the block is
    the count of entities in the definition. The test below
    seems to confirm this.

    Sub T()
    Dim b As AcadBlock
    For Each b In ThisDrawing.Blocks
    If b.IsXRef And b.Count = 0 Then
    MsgBox (b.Name & " is an unloaded xref")
    b.Detach
    End If
    Next
    End Sub
     
    AKS, Nov 12, 2004
    #3
  4. AKS

    pkirill Guest

    Here's my sub for detaching all xrefs. It doesn't expressly identify
    unloaded xrefs, but will detach all xrefs, unloaded or not without
    quitting - like -xref>detach will.


    Dim acad As New AcadApplication
    Dim dwg As AcadDocument

    Public Sub cmdDetXref()

    For Each blkMyBlock In dwg.Blocks
    On Error Resume Next
    If blkMyBlock.IsXRef Then
    If Err Then
    GoTo MOVEON1
    End If
    dwg.Blocks.Item(blkMyBlock.Name).Detach
    End If
    MOVEON1:
    Next blkMyBlock
    For Each blkMyBlock In dwg.Blocks
    On Error Resume Next
    If blkMyBlock.IsXRef Then
    If Err Then
    GoTo MOVEON2
    End If
    dwg.Blocks.Item(blkMyBlock.Name).Detach
    End If
    MOVEON2:
    Next blkMyBlock
    dwg.PurgeAll
    On Error GoTo 0

    End Sub
     
    pkirill, Nov 16, 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.