Jump to content

Batch Inserting Blocks with VBA Hangs up on second drawing?


muck

Recommended Posts

AutoCAD 2010 vba.

 

The following code is for a batch block insert.

Batch Inserting Blocks with VBA Hangs up on second drawing?

The process stops on the second drawing at line

Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(startPnt, "C:\BlockInsert.Dwg", 1#, 1#, 1#, 0)

If I rename C:\BlockInsert.Dwg to C:\BlockInsert1.dwg durring debug the code will execute.

I don't see where I have duplicate blocks my drawing because of my purges.

Anyone have any suggestion to fix this?

Thank you,

 

 

Private Sub CommandButton3_Click()

Dim toggle As Boolean

toggle = True

Me.Hide

Dim zcount As Integer

DrawingList.VBDwgFileList

AutoCAD.Documents.Close

For zcount = 0 To DrawingList.filecount - 1

FileName = DrawingList.VBDwgFileNames(zcount)

 

If FileName "" Then AutoCAD.Documents.Open (FileName)

If Application.Documents.Count = 0 Then

MsgBox "Empty AutoCAD Editor"

Exit Sub

End If

InsertBlockName = "BlockInsert.Dwg"

'****

ThisDrawing.PurgeAll

ThisDrawing.SendCommand "-Purge" & vbCr & "B" & vbCr & "*" & vbCr & "N" & vbCr

startPnt = ThisDrawing.Utility.GetPoint(, prompt1)

Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(startPnt, "C:\BlockInsert.Dwg", 1#, 1#, 1#, 0)

BlockRefObj.Explode

BlockRefObj.Delete

ThisDrawing.PurgeAll

Debug.Print FileName

ThisDrawing.Save 'Save the drawing

ThisDrawing.Close

'Debug.Print zcount

If zcount = DrawingList.filecount - 1 Then Exit Sub

Next

Me.Show

End Sub

Link to comment
Share on other sites

So if I have my routine to run through all the files and purge them then go

back and insert the blocks. That might work? I will give that a try

I notice that the VBA statement Thisdrawing.purgeall does not get all blocks.

The command send for purge does. That is why I am using the command send here.

Any other suggestions?

Thank you,

Link to comment
Share on other sites

I saperated the routines into purge then insert block as follows.

That did not work.

 

Private Sub CommandButton3_Click()

Dim toggle As Boolean

toggle = True

Me.Hide

Dim zcount As Integer

DrawingList.VBDwgFileList

AutoCAD.Documents.Close

For zcount = 0 To DrawingList.filecount - 1

FileName = DrawingList.VBDwgFileNames(zcount)

 

If FileName "" Then AutoCAD.Documents.Open (FileName)

If Application.Documents.Count = 0 Then

MsgBox "Empty AutoCAD Editor"

Exit Sub

End If

InsertBlockName = "BlockInsert.Dwg"

ThisDrawing.PurgeAll

ThisDrawing.SendCommand "-Purge" & vbCr & "B" & vbCr & "*" & vbCr & "N" & vbCr

Debug.Print FileName

ThisDrawing.Save 'Save the drawing

ThisDrawing.Close

If zcount = DrawingList.filecount - 1 Then Exit Sub

Next

Me.Show

End Sub

Private Sub CommandButton11_Click()

Dim toggle As Boolean

toggle = True

Me.Hide

Dim zcount As Integer

DrawingList.VBDwgFileList

AutoCAD.Documents.Close

For zcount = 0 To DrawingList.filecount - 1

FileName = DrawingList.VBDwgFileNames(zcount)

 

If FileName "" Then AutoCAD.Documents.Open (FileName)

If Application.Documents.Count = 0 Then

MsgBox "Empty AutoCAD Editor"

Exit Sub

End If

 

Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(startPnt, "C:\BlockInsert.Dwg", 1#, 1#, 1#, 0)

BlockRefObj.Explode

BlockRefObj.Delete

ThisDrawing.PurgeAll

Debug.Print FileName

ThisDrawing.Save 'Save the drawing

ThisDrawing.Close

If zcount = DrawingList.filecount - 1 Then Exit Sub

Next

Me.Show

End Sub

Any other suggestions?

Link to comment
Share on other sites

Does the incoming drawing, "BlockInsert.Dwg", itself contain Blocks.

At the database level (the level at which VBA operates) a purge operations only affects the top most block layer, nested block are still considered referenced until after that top layer is deleted. ThisDrawing.PurgeAll would have to be called for each nesting level.*

Sadly, VBA does not handle ThisDrawing.SendCommand well so any result from a SendCommand call will not be available until after the entire routine has run.

What VBA should be able to do, though, is continually loop a PurgeAll call until none of the blocks associated with BlockInsert.Dwg are present.

* Presumably, there is a ObjectARX multi-iteration purge happening behind the scenes with AutoCAD’s Command: -Purge.

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...