.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data Extraction to Table

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
BrentBurgess1980
1529 Views, 2 Replies

Data Extraction to Table

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

2 REPLIES 2
Message 2 of 3

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

Message 3 of 3

Thanks Balaji.

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost