I want help regarding a data extraction program that I am using to obtain attribute information from blocks inside the dwg files.
I got the basic code online which I modified to suit my needs. Still, this portion is exactly the same. (Link of the thread for the source)
The steps are:
- This code generates a DLL library upon build,
- which I then load in AutoCAD 2012 using the "NETLOAD" command;
- After that I run the command "ATT2CSV" (defined in this code),
- which gives me the output file.
Currently, the program retrieves every DWG file from the "c:\temp\drawings" path; but I want the program to extract the data just from the calling instance.
This Interop and API jargon is all alien to me; the only way I could even get this to work was because of that godsent link.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace AttExt
{
public class cadextract
{
[CommandMethod("Att2Csv")]
public void AttributesToCsv()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
string dwgPath = @"c:\temp\drawings";
string csvPathname = @"c:\temp\drawings\AtEx.csv";
if (File.Exists(csvPathname))
File.Delete(csvPathname);
ed.WriteMessage(doc.ToString());
foreach (var dwgPathname in Directory.GetFiles(dwgPath, "*.dwg",
SearchOption.AllDirectories))
{
ed.WriteMessage("\nProcessing: {0}", dwgPathname);
AttExt(dwgPathname, csvPathname);
}
}
public void AttExt(string dwgPathname, string csvPathname)
{
....function defined here...
}
}
}
Thanks in advance!