.NET

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

Data Extraction to Table

531 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

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 2 of 3 (441 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: 161
Registered: ‎06-16-2008
Message 3 of 3 (434 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!!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community