<?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 Runtime exception : eKey not found on plugin in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/6575791#M34484</link>
    <description>&lt;P&gt;I'm writing a plug-in for ACAD 2012 that makes a data extraction and outputs it to a txt file. I am developing on VS2015; targeting the .Net 3.5 framework.&lt;/P&gt;&lt;P&gt;I have been debugging a script that uses the code for the data extraction class based on &lt;A href="http://adndevblog.typepad.com/autocad/2013/04/linking-attributes-and-table-using-dataextraction-api.html" target="_blank"&gt;this post &lt;/A&gt;. however, when the command runs, I get an error at the line&amp;nbsp; setting.DrawingDataExtractor.DiscoverTypesAndProperties(dwgpath); which causes &amp;nbsp;Autocad to throw a runtime exception: eKeyNotFound.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I traced the stack calls and the error says it is in the &amp;nbsp;AcdbMgd.dll that the error is being thrown; Stack trace and command code &amp;nbsp;function included below. I Don't really know where to go from here. AutoCAD seems to recover on small dwgs after throwing the error, but on a more complex dwg, it just throws the exception repeatedly and stalls out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Exception detail

Autodesk.AutoCAD.Runtime.Exception occurred
  HResult=-2146233088
  Message=eKeyNotFound
  Source=Acdbmgd
  StackTrace:
       at Autodesk.AutoCAD.DatabaseServices.Database.get_GeoDataObject()


The rest of the stack call back to my source function :
AcdbMgd.dll!Autodesk.AutoCAD.DatabaseServices.Database.GeoDataObject.get()
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GeoObjectId.get()	
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GetEntityTypeIndex(System.Collections.Generic.List&amp;lt;Autodesk.AutoCAD.DatabaseServices.Handle&amp;gt; selectedObjects, Autodesk.AutoCAD.DataExtraction.ExtractFlags flags)
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GetEntityTypeIndex(Autodesk.AutoCAD.DataExtraction.ExtractFlags flags)
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DxDrawingDataExtractor.DiscoverTypesAndProperties(string rootdir)	Unknown
&amp;gt;	BomChecker.dll!BomChecker.TesterClass.dxeGetData() Line 154
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(System.Reflection.MethodInfo mi, object commandObject, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(System.Reflection.MethodInfo mi, object commandObject, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.Invoke(System.Reflection.MethodInfo mi, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()	&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.DataExtraction;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(BomChecker.TesterClass))]

namespace BomChecker
{
 public class TesterClass
 {
 
[CommandMethod("GetText")]
public static void dxeGetData()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            //logic to scrub for a dxe file near the doc.name still needed, we will use the dwg name for simplicity
            string dwgpath = doc.Name;
            string dwgname = "";
            string othername = "";
            string pattern = @"[a-z,A-Z,0-9,\s]+.dwg";//pattern to find any names of a .dwg file
            Regex regex = new Regex(pattern);
            Match match = regex.Match(dwgpath);
            if (match.Success)
            {
                dwgname = match.Value;
                int i = dwgname.LastIndexOf(".");
                othername = dwgname.Substring(0, i);
            }
            else { othername = "test"; }

            string dwgFolder = System.IO.Directory.GetParent(dwgpath).ToString();
            string dxePath = System.IO.Path.Combine(dwgFolder, othername + ".dxe");
            string txtpath = System.IO.Path.Combine(dwgFolder, othername + ".txt");
            if (System.IO.File.Exists(dxePath) == false)
            {

                // Create the DXE file with the information that we want to extract
                DxExtractionSettings setting = new DxExtractionSettings();

                IDxFileReference dxFileReference
                    = new DxFileReference(dwgFolder, dwgpath);

                setting.DrawingDataExtractor.Settings.DrawingList.AddFile
                                                        (dxFileReference);
                // this is where everything breaks down
                setting.DrawingDataExtractor.DiscoverTypesAndProperties
                                                    (dwgpath);

                List&amp;lt;IDxTypeDescriptor&amp;gt; types
                    = setting.DrawingDataExtractor.DiscoveredTypesAndProperties;

                List&amp;lt;string&amp;gt; selectedTypes = new List&amp;lt;string&amp;gt;();
                List&amp;lt;string&amp;gt; selectedProps = new List&amp;lt;string&amp;gt;();
                foreach (IDxTypeDescriptor td in types)
                {
                    if (td.GlobalName.Equals("Autodesk.AutoCAD.DatabaseServices.MText") ||
                        td.GlobalName.Equals("Autodesk.AutoCAD.DatabaseServices.DBText"))
                        selectedTypes.Add(td.GlobalName);

                    foreach (IDxPropertyDescriptor pd in td.Properties)
                    {
                        if (pd.GlobalName.Equals("TextString") ||
                            pd.GlobalName.Equals("Contents"))
                        {
                            if (!selectedProps.Contains(pd.GlobalName))
                                selectedProps.Add(pd.GlobalName);
                        }
                    }
                }

                setting.DrawingDataExtractor.Settings.ExtractFlags
                                = ExtractFlags.Nested | ExtractFlags.Xref;

                setting.DrawingDataExtractor.Settings.SetSelectedTypesAndProperties
                                    (types, selectedTypes, selectedProps);


                setting.OutputSettings.FileOutputType = AdoOutput.OutputType.tabSystemDefault;
                setting.OutputSettings.ManuallySetupTable = false;
                setting.OutputSettings.OuputFlags = DxOuputFlags.File;
                setting.OutputSettings.FileName = txtpath;
                setting.OutputSettings.TableStyleId = db.Tablestyle;
                setting.OutputSettings.UsePropertyNameAsColumnHeader = false;


                setting.Save(dxePath);
            }
DxExtractionSettings setting2 = (DxExtractionSettings)DxExtractionSettings.FromFile(dxePath);
 bool checkbool = setting2.DrawingDataExtractor.ExtractData(dwgpath);
 if (checkbool)
 {
 AdoOutput.SaveDataTableToFile(txtpath, setting2.DrawingDataExtractor.ExtractedData, AdoOutput.OutputType.tabSystemDefault);

}
} 
}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2016 14:43:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-09-21T14:43:14Z</dc:date>
    <item>
      <title>Runtime exception : eKey not found on plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/6575791#M34484</link>
      <description>&lt;P&gt;I'm writing a plug-in for ACAD 2012 that makes a data extraction and outputs it to a txt file. I am developing on VS2015; targeting the .Net 3.5 framework.&lt;/P&gt;&lt;P&gt;I have been debugging a script that uses the code for the data extraction class based on &lt;A href="http://adndevblog.typepad.com/autocad/2013/04/linking-attributes-and-table-using-dataextraction-api.html" target="_blank"&gt;this post &lt;/A&gt;. however, when the command runs, I get an error at the line&amp;nbsp; setting.DrawingDataExtractor.DiscoverTypesAndProperties(dwgpath); which causes &amp;nbsp;Autocad to throw a runtime exception: eKeyNotFound.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I traced the stack calls and the error says it is in the &amp;nbsp;AcdbMgd.dll that the error is being thrown; Stack trace and command code &amp;nbsp;function included below. I Don't really know where to go from here. AutoCAD seems to recover on small dwgs after throwing the error, but on a more complex dwg, it just throws the exception repeatedly and stalls out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Exception detail

Autodesk.AutoCAD.Runtime.Exception occurred
  HResult=-2146233088
  Message=eKeyNotFound
  Source=Acdbmgd
  StackTrace:
       at Autodesk.AutoCAD.DatabaseServices.Database.get_GeoDataObject()


The rest of the stack call back to my source function :
AcdbMgd.dll!Autodesk.AutoCAD.DatabaseServices.Database.GeoDataObject.get()
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GeoObjectId.get()	
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GetEntityTypeIndex(System.Collections.Generic.List&amp;lt;Autodesk.AutoCAD.DatabaseServices.Handle&amp;gt; selectedObjects, Autodesk.AutoCAD.DataExtraction.ExtractFlags flags)
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DatabaseWrapper.GetEntityTypeIndex(Autodesk.AutoCAD.DataExtraction.ExtractFlags flags)
 	AcDx.dll!Autodesk.AutoCAD.DataExtraction.DxDrawingDataExtractor.DiscoverTypesAndProperties(string rootdir)	Unknown
&amp;gt;	BomChecker.dll!BomChecker.TesterClass.dxeGetData() Line 154
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(System.Reflection.MethodInfo mi, object commandObject, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(System.Reflection.MethodInfo mi, object commandObject, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.Invoke(System.Reflection.MethodInfo mi, bool bLispFunction)	
 	acmgd.dll!Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()	&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.DataExtraction;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(BomChecker.TesterClass))]

namespace BomChecker
{
 public class TesterClass
 {
 
[CommandMethod("GetText")]
public static void dxeGetData()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            //logic to scrub for a dxe file near the doc.name still needed, we will use the dwg name for simplicity
            string dwgpath = doc.Name;
            string dwgname = "";
            string othername = "";
            string pattern = @"[a-z,A-Z,0-9,\s]+.dwg";//pattern to find any names of a .dwg file
            Regex regex = new Regex(pattern);
            Match match = regex.Match(dwgpath);
            if (match.Success)
            {
                dwgname = match.Value;
                int i = dwgname.LastIndexOf(".");
                othername = dwgname.Substring(0, i);
            }
            else { othername = "test"; }

            string dwgFolder = System.IO.Directory.GetParent(dwgpath).ToString();
            string dxePath = System.IO.Path.Combine(dwgFolder, othername + ".dxe");
            string txtpath = System.IO.Path.Combine(dwgFolder, othername + ".txt");
            if (System.IO.File.Exists(dxePath) == false)
            {

                // Create the DXE file with the information that we want to extract
                DxExtractionSettings setting = new DxExtractionSettings();

                IDxFileReference dxFileReference
                    = new DxFileReference(dwgFolder, dwgpath);

                setting.DrawingDataExtractor.Settings.DrawingList.AddFile
                                                        (dxFileReference);
                // this is where everything breaks down
                setting.DrawingDataExtractor.DiscoverTypesAndProperties
                                                    (dwgpath);

                List&amp;lt;IDxTypeDescriptor&amp;gt; types
                    = setting.DrawingDataExtractor.DiscoveredTypesAndProperties;

                List&amp;lt;string&amp;gt; selectedTypes = new List&amp;lt;string&amp;gt;();
                List&amp;lt;string&amp;gt; selectedProps = new List&amp;lt;string&amp;gt;();
                foreach (IDxTypeDescriptor td in types)
                {
                    if (td.GlobalName.Equals("Autodesk.AutoCAD.DatabaseServices.MText") ||
                        td.GlobalName.Equals("Autodesk.AutoCAD.DatabaseServices.DBText"))
                        selectedTypes.Add(td.GlobalName);

                    foreach (IDxPropertyDescriptor pd in td.Properties)
                    {
                        if (pd.GlobalName.Equals("TextString") ||
                            pd.GlobalName.Equals("Contents"))
                        {
                            if (!selectedProps.Contains(pd.GlobalName))
                                selectedProps.Add(pd.GlobalName);
                        }
                    }
                }

                setting.DrawingDataExtractor.Settings.ExtractFlags
                                = ExtractFlags.Nested | ExtractFlags.Xref;

                setting.DrawingDataExtractor.Settings.SetSelectedTypesAndProperties
                                    (types, selectedTypes, selectedProps);


                setting.OutputSettings.FileOutputType = AdoOutput.OutputType.tabSystemDefault;
                setting.OutputSettings.ManuallySetupTable = false;
                setting.OutputSettings.OuputFlags = DxOuputFlags.File;
                setting.OutputSettings.FileName = txtpath;
                setting.OutputSettings.TableStyleId = db.Tablestyle;
                setting.OutputSettings.UsePropertyNameAsColumnHeader = false;


                setting.Save(dxePath);
            }
DxExtractionSettings setting2 = (DxExtractionSettings)DxExtractionSettings.FromFile(dxePath);
 bool checkbool = setting2.DrawingDataExtractor.ExtractData(dwgpath);
 if (checkbool)
 {
 AdoOutput.SaveDataTableToFile(txtpath, setting2.DrawingDataExtractor.ExtractedData, AdoOutput.OutputType.tabSystemDefault);

}
} 
}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 14:43:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/6575791#M34484</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-21T14:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Runtime exception : eKey not found on plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/6576008#M34485</link>
      <description>Never mind, apparently the hang time was caused by the extra info in the Debug version of the dll. the Release configuration had no such issues when loaded in autocad (not debugging)</description>
      <pubDate>Wed, 21 Sep 2016 15:56:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/6576008#M34485</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-21T15:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Runtime exception : eKey not found on plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/10665364#M34486</link>
      <description>&lt;P&gt;Hi friend, did you manage to find a solution? I'm experiencing a similar problem.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 14:43:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/runtime-exception-ekey-not-found-on-plugin/m-p/10665364#M34486</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-04T14:43:53Z</dc:date>
    </item>
  </channel>
</rss>

