Jump to content

AutoCAD VBA - Object was Erased error when binding xref's


sdubbs

Recommended Posts

I have the following code to bind all xref's in a drawing. For some reason, I am getting an "Object was erased" error when the blk.bind is attempted. If I manually bind the xref in AutoCAD it works fine.

 
Private Sub bindXrefs()
   'On Error Resume Next
   'Bind all xrefs (if g.a.) and save
   Set Blocks = ThisDrawing.Blocks
   For Each blk In Blocks
       'Detach unloaded xrefs
       If blk.IsXRef Then
           If blk.Count < 2 Then
               'Detach unloaded xref
               blk.Detach
           Else
               blk.Bind False
           End If
       End If
   Next
End Sub

Link to comment
Share on other sites

The code below was probably one of the first things I did with VBA and hasn't been looked at for a good few years now, but as far as I remember it worked fine.

Dim blk As AcadBlock
Count = ThisDrawing.Blocks.Count - 1
While Count >= 0
   Set blk = ThisDrawing.Blocks.Item(Count)
       If blk.IsXRef Then
       On Error Resume Next
       blk.Bind False
On Error Resume Next
End If
   Count = Count - 1
Wend
On Error GoTo 0
binderror:
Count = Count

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...