<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: VBA Add document then Add layer got -2147418111 Automation error in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3914214#M11167</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#666699"&gt;&amp;gt;&amp;gt; I got an error when add a layer after creating a new document&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Sorry, I don't get exceptions when I run your code without time-loops (which should not be necessary at least).&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you might try "DoEvents" instead of the time-loops:&lt;/P&gt;&lt;PRE&gt;AddDrawingInfoLayer 'if I use this line directly,then will get an error: -2147418111 Automation error
&lt;EM&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;DoEvents&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;
' 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&lt;/PRE&gt;&lt;P&gt;And - I guess you know that - AutoCAD 2013 is not supported for Win8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2013 04:40:52 GMT</pubDate>
    <dc:creator>Alfred.NESWADBA</dc:creator>
    <dc:date>2013-05-09T04:40:52Z</dc:date>
    <item>
      <title>VBA Add document then Add layer got -2147418111 Automation error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3914178#M11166</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I got an error when add a layer after creating a new document, do you have any suggession?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Env.&lt;/P&gt;&lt;PRE&gt; 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 &amp;amp; " sleep " &amp;amp; sleepCount &amp;amp; " seconds"
        ThisDrawing.SaveAs "C:\temp\" &amp;amp; i &amp;amp; ".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 &amp;lt; varStart + seconds
    Loop
End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Autocad 2013 64bit, windows 8 64bit. 8GB ram and i7-3770 cpu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 02:04:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3914178#M11166</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-09T02:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Add document then Add layer got -2147418111 Automation error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3914214#M11167</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#666699"&gt;&amp;gt;&amp;gt; I got an error when add a layer after creating a new document&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Sorry, I don't get exceptions when I run your code without time-loops (which should not be necessary at least).&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you might try "DoEvents" instead of the time-loops:&lt;/P&gt;&lt;PRE&gt;AddDrawingInfoLayer 'if I use this line directly,then will get an error: -2147418111 Automation error
&lt;EM&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;DoEvents&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;
' 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&lt;/PRE&gt;&lt;P&gt;And - I guess you know that - AutoCAD 2013 is not supported for Win8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 04:40:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3914214#M11167</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2013-05-09T04:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Add document then Add layer got -2147418111 Automation error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3915002#M11168</link>
      <description>&lt;P&gt;Thanks very much for your reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 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!&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 10:54:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3915002#M11168</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-09T10:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Add document then Add layer got -2147418111 Automation error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3915503#M11169</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#666699"&gt;&amp;gt;&amp;gt; I don't know why&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Again the question: do you have the layermanager open while your code runs (and crashes)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 17:31:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/vba-add-document-then-add-layer-got-2147418111-automation-error/m-p/3915503#M11169</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2013-05-09T17:31:02Z</dc:date>
    </item>
  </channel>
</rss>

