muck
9th Sep 2010, 07:11 pm
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
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