2014-08-28 59 views
0

我想获得关于我用于从dwg文件中的块获取属性信息的数据提取程序的帮助。使用C#生成的DLL库访问AutoCAD的调用实例

我得到了我修改的基本代码,以适合我的需要。不过,这部分是完全一样的。 (Link of the thread for the source)

的步骤是:

  1. 此代码生成时生成一个DLL图书馆,
  2. 然后我在2012年的AutoCAD使用 “NETLOAD” 命令加载;
  3. 之后,我运行命令“ATT2CSV”(在此代码中定义),
  4. 它给了我输出文件。

目前,该程序从“c:\ temp \ drawings”路径中检索每个DWG文件;但是我希望程序仅从调用实例中提取数据。

这个Interop和API术语对我来说都是陌生的;我甚至可以让这个工作起作用的唯一途径就是因为那个上帝的联系。

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... 
    } 
    } 
} 

在此先感谢!

回答

1

快速和肮脏的方法是只删除foreach循环,只是用当前名称调用AttExt函数。我习惯了VB.net所以我不太确定C#语法。

在VB:

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

'Start the Function AttExt 
AttExt(currentpath , csvPathname) 

干杯, 阿兰

+0

非常感谢你的帮助;它完美无缺地工作! – Govinda 2014-08-28 07:32:34