0

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:

  1. This code generates a DLL library upon build,
  2. which I then load in AutoCAD 2012 using the "NETLOAD" command;
  3. After that I run the command "ATT2CSV" (defined in this code),
  4. 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!

Govinda
  • 61
  • 11

1 Answers1

1

The quick and dirty way is to just remove the foreach loop and just call the AttExt function with the current name. I'm used to VB.net So i'm not quite sure of the C# syntax.

In VB:

'First get the current drawing path
Dim currentpath =  doc.Name

'Start the Function AttExt
AttExt( currentpath , csvPathname )

Cheers, Alain

Govinda
  • 61
  • 11
Alain
  • 304
  • 3
  • 9