0
我想获得关于我用于从dwg文件中的块获取属性信息的数据提取程序的帮助。使用C#生成的DLL库访问AutoCAD的调用实例
我得到了我修改的基本代码,以适合我的需要。不过,这部分是完全一样的。 (Link of the thread for the source)
的步骤是:
- 此代码生成时生成一个DLL图书馆,
- 然后我在2012年的AutoCAD使用 “NETLOAD” 命令加载;
- 之后,我运行命令“ATT2CSV”(在此代码中定义),
- 它给了我输出文件。
目前,该程序从“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...
}
}
}
在此先感谢!
非常感谢你的帮助;它完美无缺地工作! – Govinda 2014-08-28 07:32:34