How does one detect an unloaded xref in VBA? tia, aks
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.
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
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