- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
I have been debugging a script that uses the code for the data extraction class based on this post . however, when the command runs, I get an error at the line setting.DrawingDataExtractor.DiscoverTypesAndProperties(dwgpath); which causes Autocad to throw a runtime exception: eKeyNotFound.
I traced the stack calls and the error says it is in the AcdbMgd.dll that the error is being thrown; Stack trace and command code 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.
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<Autodesk.AutoCAD.DatabaseServices.Handle> 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
> 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()
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<IDxTypeDescriptor> types
= setting.DrawingDataExtractor.DiscoveredTypesAndProperties;
List<string> selectedTypes = new List<string>();
List<string> selectedProps = new List<string>();
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);
}
}
}
}
Solved! Go to Solution.