- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm stuck with something that I think should be quite simple: I have a drawing with multiple blocks in it. Based on some conditions (this part os O.K to me) the macro should pick one of the blocks, copy it and paste into another drawing.
I'm not experienced in Autocad VBA, but I'm used to Excel VBA, and thus, although I don't know to achieve want I want to do, it seems to be simple. However, looking around in this forum I found some very complicated solutions to similar questions and I thought: there must be a simpler way.
Can anyone help me out with this?
The seemingly straight-forward method Drawing.CopyObjects doesn't work for me. It throws the error: CopyObjects failed, with code -2145320837 (8021007b)
Sub CopyingBlock()
Dim myBlock As AcadBlockReference
Dim oEnt As AcadEntity
Dim newPoint(0 To 2) As Double
newPoint(0) = 0
newPoint(1) = 0
newPoint(2) = 0
Dim blockName As String
blockName = "Teste"
For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadBlockReference Then
Set myBlock = oEnt
If myBlock.Name = blockName Then
Dim awCopy As AcadDocument
Set awCopy = ThisDrawing
Dim awPaste As AcadDocument
Set awPaste = Application.Documents.Open("D:\Users\charley_r\Desktop\TesteFernandinhoPaste.dwg")
awCopy.CopyObjects myBlock, awPaste.ModelSpace
End If
End If
Next oEnt
End Sub
Solved! Go to Solution.