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!
Hi,
>> I got an error when add a layer after creating a new document
Sorry, I don't get exceptions when I run your code without time-loops (which should not be necessary at least).
The only idea I have is you have anything running parallel that "reacts" on layer additions/modifications, e.g. do you have the layermanager open while running your code? Or do you have any applications/apps/tools installed?
What you might try "DoEvents" instead of the time-loops:
AddDrawingInfoLayer 'if I use this line directly,then will get an error: -2147418111 Automation error DoEvents ' 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
And - I guess you know that - AutoCAD 2013 is not supported for Win8.
- alfred -
Thanks very much for your reply!
I don't know why, if I delete wait code, then the layer cannot created, and if I change to "Wati 0", then i can work. Strange. I will test your code, thanks again!
Hi,
>> I don't know why
Again the question: do you have the layermanager open while your code runs (and crashes)?
- alfred -