<?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: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database. in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762433#M14241</link>
    <description>&lt;P&gt;wrong forum?&lt;/P&gt;&lt;P&gt;btr.Dispose(); seems incorrect since it's part of the transaction&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2024 10:39:57 GMT</pubDate>
    <dc:creator>daniel_cadext</dc:creator>
    <dc:date>2024-05-09T10:39:57Z</dc:date>
    <item>
      <title>Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12761990#M14240</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;(ok so I posted this in the wrong forum by mistake. Should be in .NET forum. Don't know how to delete question. Posted the same question in &amp;gt;NET forum.)&lt;/P&gt;&lt;P&gt;I've created a c# .NET plugin for autocad which adds a command. I have has a macro in an excel file which starts autocad and runs the plugin command which gets the input through excel file and then creates what is required.&lt;/P&gt;&lt;P&gt;The plugin needs to import blocks from another drawing and I'm using&amp;nbsp;WblockCloneObjects to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used the same import code till now without any issues.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the macro through excel I'm randomly getting&amp;nbsp;fatal error access violation error with autocad crashing at&amp;nbsp;WblockCloneObjects line. This happens randomly when starting through excel macro. (Happened only once in debug mode, can't replicate the error again in debug mode.)&lt;/P&gt;&lt;P&gt;I'm using AutoCAD mechanical 2020.&lt;/P&gt;&lt;P&gt;In excel, I've reference AutoCAD 2019 Type Library(can't find for 2020) and AutoCAD Mechanical 2020 Type Library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can any one please help?&lt;/P&gt;&lt;P&gt;I'm attaching the error details, the import code and application starting code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error shown from the dump file:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ShricharanaB_0-1715232811612.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1359990i2341265D748C097C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ShricharanaB_0-1715232811612.png" alt="ShricharanaB_0-1715232811612.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Call stack:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ShricharanaB_1-1715232865466.png" style="width: 900px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1359991i95593CAB222518C4/image-dimensions/900x63?v=v2" width="900" height="63" role="button" title="ShricharanaB_1-1715232865466.png" alt="ShricharanaB_1-1715232865466.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Full first line in call stack:&lt;/P&gt;&lt;P&gt;&amp;gt; Acdbmgd.dll!Autodesk.AutoCAD.DatabaseServices.Database.WblockCloneObjects(Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection identifiers, Autodesk.AutoCAD.DatabaseServices.ObjectId id, Autodesk.AutoCAD.DatabaseServices.IdMapping mapping, Autodesk.AutoCAD.DatabaseServices.DuplicateRecordCloning cloning, bool deferTranslation) Line 6207 C#&lt;/P&gt;&lt;P&gt;Import Method being used:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Checks if given block names exist in given block table and imports all blocks from given drawng if not.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="blockNamesToCheck"&amp;gt;Array of block names to check.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="drawingPaths"&amp;gt;import location of the blocks.&amp;lt;/param&amp;gt;
public static void ImportBlocks(string[] blockNamesToCheck, string sourceFileName)
{

    DocumentCollection dm = Application.DocumentManager;
    Editor ed = dm.MdiActiveDocument.Editor;
    Database destDb = dm.MdiActiveDocument.Database;
    Database sourceDb = new Database(false, true);
    //string sourceFileName;
    if (!ShouldImport(destDb, blockNamesToCheck))
    {
        return;
    }
    try
    {
        // Read the DWG into a side database
        sourceDb.ReadDwgFile(sourceFileName, FileOpenMode.OpenForReadAndAllShare, false, null);


        // Create a variable to store the list of block identifiers
        ObjectIdCollection blockIds = new ObjectIdCollection();

        Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;

        using (Transaction myT = tm.StartTransaction())
        {
            // Open the block table
            BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

            // Check each block in the block table
            foreach (ObjectId btrId in bt)
            {
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);

                // Only add named &amp;amp; non-layout blocks to the copy list
                if (!btr.IsAnonymous &amp;amp;&amp;amp; !btr.IsLayout) blockIds.Add(btrId);
                btr.Dispose();
            }
        }

        // Copy blocks from source to destination database
        IdMapping mapping = new IdMapping();
        sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
        // ed.WriteMessage("\nCopied " + blockIds.Count.ToString() + " block definitions from " + sourceFileName + " to the current drawing.");
        ed.WriteMessage("Blocks imported.");


    }
    catch (Autodesk.AutoCAD.Runtime.Exception ex)
    {
        ed.WriteMessage("\nError during copy: " + ex.Message);
        throw new Exception(ex.Message);
    }
    sourceDb.Dispose();
}&lt;/LI-CODE&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;&lt;P&gt;VBA code in Excel Macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim ACAD As AcadApplication
Dim NewFile As Object
Dim MyAcadPath As String
Dim bReadOnly As Boolean
    
    On Error Resume Next
    Set ACAD = GetObject(, "autocad.Application")
    If (Err &amp;lt;&amp;gt; 0) Then
        Err.Clear
        Set ACAD = CreateObject("autocad.Application")
        If (Err &amp;lt;&amp;gt; 0) Then
            MsgBox "Could Not Load AutoCAD!", vbExclamation
            End
        End If
    End If

    ACAD.Visible = True
    MyAcadPath = "C:\Autodesk\Drawing.dwg"

    bReadOnly = True
    Set NewFile = ACAD.Documents.Open(MyAcadPath, bReadOnly)
    Call CreateInputString
    NewFile.SendCommand cmd&lt;/LI-CODE&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;&lt;P&gt;References being used in excel macro&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ShricharanaB_2-1715233065254.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1359992iE5E0FB4202FBACD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ShricharanaB_2-1715233065254.png" alt="ShricharanaB_2-1715233065254.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate any help.&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 2024 08:29:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12761990#M14240</guid>
      <dc:creator>ShricharanaB</dc:creator>
      <dc:date>2024-05-09T08:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762433#M14241</link>
      <description>&lt;P&gt;wrong forum?&lt;/P&gt;&lt;P&gt;btr.Dispose(); seems incorrect since it's part of the transaction&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 10:39:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762433#M14241</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2024-05-09T10:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762462#M14242</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah posted on the wrong forum by mistake.&lt;/P&gt;&lt;P&gt;even if the dispose is left in place, it shouldn't cause any issues right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tried after removing the btr.Dispose();, AutoCAD still crashes randomly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 11:02:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762462#M14242</guid>
      <dc:creator>ShricharanaB</dc:creator>
      <dc:date>2024-05-09T11:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762736#M14243</link>
      <description>&lt;P&gt;Lost all my .NET skills lol. I think I would try&lt;/P&gt;&lt;P&gt;sourceDb.closeinput so you know the database is fully read into memory&lt;/P&gt;&lt;P&gt;also I forget if you have to set the source/dest database in mapping&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2024 13:20:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12762736#M14243</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2024-05-09T13:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764119#M14244</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you for the suggestion.&lt;/P&gt;&lt;P&gt;I tried adding sourceDB.CloseInput(true) to the code. But AutoCAD is still crashing randomly on WblockCloneObjects line in Database.CS. Particularly this line&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Autodesk.AutoCAD.Runtime.Interop.Check((int)_003CModule_003E.AcDbDatabase_002EwblockCloneObjects(GetImpObj(), identifiers.GetImpObj(), (AcDbObjectId*)(&amp;amp;id), mapping.GetImpObj(), (AcDb.DuplicateRecordCloning)cloning, deferTranslation));&lt;/LI-CODE&gt;&lt;P&gt;This is how I've added the code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;sourceDb.ReadDwgFile(sourceFileName, FileOpenMode.OpenForReadAndAllShare, false, null);
sourceDb.CloseInput(true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 04:28:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764119#M14244</guid>
      <dc:creator>ShricharanaB</dc:creator>
      <dc:date>2024-05-10T04:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764122#M14245</link>
      <description>&lt;P&gt;Can you catch the error message?&lt;/P&gt;&lt;P&gt;Interop.Check should pass up an Arx Acad::ErrorStatus value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 04:33:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764122#M14245</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2024-05-10T04:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting fatal error access violation when using WblockCloneObjects to clone blocks from another drawing database.</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764206#M14246</link>
      <description>&lt;P&gt;The code is within the try - catch block, but it doesn't catch the access violation fatal error I'm getting.&amp;nbsp; I'm don't know how to use&amp;nbsp;&lt;SPAN&gt;Interop.Check, could you please give me an example?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 05:48:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/getting-fatal-error-access-violation-when-using/m-p/12764206#M14246</guid>
      <dc:creator>ShricharanaB</dc:creator>
      <dc:date>2024-05-10T05:48:16Z</dc:date>
    </item>
  </channel>
</rss>

