Message 1 of 4
VBA Add document then Add layer got -2147418111 Automation error
Not applicable
05-08-2013
06:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all,
I got an error when add a layer after creating a new document, do you have any suggession?
Env.
Sub test()
On Error GoTo err_handle
Dim app As AcadApplication
Dim sleepCount As Long
Set app = GetObject(, "AutoCAD.Application")
For i = 1 To 10
sleepCount = 0
app.Documents.add "acadiso.dwt"
'AddDrawingInfoLayer 'if I use this line directly,then will get an error: -2147418111 Automation error
' wait until the layer created, it's very slow, mornally it taks a long time to do it..
Do While AddDrawingInfoLayer = False
sleepCount = sleepCount + 1
Wait 0.01' wait 0.01 second
Loop
Debug.Print i & " sleep " & sleepCount & " seconds"
ThisDrawing.SaveAs "C:\temp\" & i & ".dwg"
ThisDrawing.Close False
Next i
Exit Sub
err_handle:
Debug.Print Err.Number
Debug.Print Err.Description
End Sub
Private Function AddDrawingInfoLayer() As Boolean
On Error GoTo err_handle
ThisDrawing.Layers.add "new_layer"
AddDrawingInfoLayer = True
Exit Function
err_handle:
AddDrawingInfoLayer = False
End Function
Private Function Wait(seconds As double)
Dim varStart As Variant
varStart = Timer
Do While Timer < varStart + seconds
Loop
End Function
Autocad 2013 64bit, windows 8 64bit. 8GB ram and i7-3770 cpu
Thanks in advance!