.NET

Reply
Mentor
BrentBurgess1980
Posts: 162
Registered: ‎06-16-2008
Message 1 of 3 (622 Views)
Accepted Solution

Data Extraction to Table

622 Views, 2 Replies
04-07-2013 09:42 PM

Hi,

 

I am working on a co-ordinate utility that utilises data extractions. I am able to extract the data that I want to an XML file, but how do I create a dxe file and link it to a table? I have found the WizardSettings has a table style, but that is as far as I have reached.

 

My code is below.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.DataExtraction;
using System.Collections.Generic;
using System.Data;
using System.IO;
using AcApp = Autodesk.AutoCAD.ApplicationServices.Application;


namespace acmCoordinates
    {
    public class DataExtraction
        {
        const string outputXmlFile = @"c:\temp\data-extract.xml";

        public static void ExtractData()
            {
            Document doc = AcApp.DocumentManager.MdiActiveDocument;

            // Create some settings for the extraction
            IDxExtractionSettings es = new DxExtractionSettings();
            IDxDrawingDataExtractor de = es.DrawingDataExtractor;
            de.Settings.ExtractFlags = ExtractFlags.ModelSpaceOnly | ExtractFlags.ExtractBlockOnly;

            // Add a single file to the settings
            IDxFileReference fr = new DxFileReference(Path.GetDirectoryName(doc.Name), doc.Name);
            de.Settings.DrawingList.AddFile(fr);
            es.WizardSettings.DisplayOptions = DisplayOptions.Block;
            es.OutputSettings.TableStyleName = AcApp.GetSystemVariable("CTABLESTYLE").ToString();
            es.OutputSettings.FileName = @"C:\Temp\DataExtraction.dxe";
            
            // Scan the drawing for object types & their properties
            de.DiscoverTypesAndProperties(Path.GetDirectoryName(doc.Name));
            List<IDxTypeDescriptor> types = de.DiscoveredTypesAndProperties;

            // Select all the types and properties for extraction
            // by adding them one-by-one to these two lists
            List<string> selTypes = new List<string>();
            List<string> selProps = new List<string>();

            //Add the ID
            foreach (IDxTypeDescriptor type in types)
                {
                if (type.GlobalName.Contains("BlockReferenceTypeDescriptor"))
                    {
                    if (type.GlobalName.ToUpper().Contains("DATUM"))
                        {
                        foreach (IDxPropertyDescriptor pr in type.Properties)
                            {
                            if (pr.Category == "Attribute")
                                {
                                selTypes.Add(type.GlobalName);
                                selProps.Add(pr.GlobalName);
                                }
                            }
                        }
                    }
                }

            //Add the Geometry
            foreach (IDxTypeDescriptor type in types)
                {
                if (type.GlobalName.Contains("BlockReferenceTypeDescriptor"))
                    {
                    if (type.GlobalName.ToUpper().Contains("DATUM"))
                        {
                        foreach (IDxPropertyDescriptor pr in type.Properties)
                            {
                            if (pr.Category == "Geometry")
                                {
                                if (pr.DisplayName.Contains("Position"))
                                    {
                                    selTypes.Add(type.GlobalName);
                                    selProps.Add(pr.GlobalName);
                                    }
                                }
                            }
                        }
                    }
                }

            // Pass this information to the extractor
            de.Settings.SetSelectedTypesAndProperties(types, selTypes, selProps);

            // Now perform the extraction itself
            de.ExtractData(Path.GetDirectoryName(doc.Name));

            //Rename Columns
            de.ExtractedData.Columns[1].ColumnName = "POINT_ID";
            de.ExtractedData.Columns[2].ColumnName = "EASTING";
            de.ExtractedData.Columns[3].ColumnName = "NORTHING";
            de.ExtractedData.Columns[4].ColumnName = "RL";
            
            // Get the results of the extraction
            System.Data.DataTable dataTable = de.ExtractedData;

            // Output the extracted data to an XML file
            if (dataTable.Rows.Count > 0)
                {
                dataTable.TableName = "Coordinate Point";
                dataTable.WriteXml(outputXmlFile);
                }
            }
        }
    }

 Any starting points would be greatly appreciated.

 

Cheers

Sorry for the delay.

 

Here is a blog post that might be some help :

http://adndevblog.typepad.com/autocad/2013/04/linking-attributes-and-table-using-dataextraction-api.html

 

 

ADN Support Specialist
Balaji_Ram
Posts: 737
Registered: ‎03-21-2011
Message 2 of 3 (532 Views)

Re: Data Extraction to Table

05-02-2013 04:23 AM in reply to: BrentBurgess1980

Sorry for the delay.

 

Here is a blog post that might be some help :

http://adndevblog.typepad.com/autocad/2013/04/linking-attributes-and-table-using-dataextraction-api....

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Mentor
BrentBurgess1980
Posts: 162
Registered: ‎06-16-2008
Message 3 of 3 (525 Views)

Re: Data Extraction to Table

05-03-2013 12:16 AM in reply to: Balaji_Ram

Thanks Balaji.

 

That seems to be exactly what I am looking to do. Many thanks for that!!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!