Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have 65 layouts in my drawings, and it takes like 20 seconds to open each. I want to insert a block into each of them using VBA. The code is working but I cannot get rid of the line that says:
ThisDrawing.ActiveLayout = lay
without failing to insert the block save for the first layout.
Is there a way to accomplish my task without having to watch CAD opening each of the layouts? I tried
Private Declare PtrSafe Function LockWindowUpdate Lib "user32" (ByVal hwndLock As LongPtr) As LongPtr
but either I don't know how to use, or it fails without telling me so (being a safe pointer maybe?)
Here is the code:
''+------------------------------------------------------------------+
''| |
''| |
''+------------------------------------------------------------------+
Sub Copy_Block_To_All_Paper_Spaces()
Dim blockRefObj As AcadBlockReference
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 2
insertionPnt(1) = 2
insertionPnt(2) = 0
Dim lay As AcadLayout
Dim sourceDoc As AcadDocument
Set sourceDoc = ActiveDocument
For Each lay In ThisDrawing.Layouts
ThisDrawing.ActiveLayout = lay ' the problematic line...
Set blockRefObj = ThisDrawing.PaperSpace.InsertBlock(insertionPnt, "MyBlockName", 1#, 1#, 1#, 0)
Next
End Sub
Solved! Go to Solution.