【问题标题】:Access the calling instance of AutoCAD using C# generated DLL library使用 C# 生成的 DLL 库访问 AutoCAD 的调用实例
【发布时间】:2014-10-21 20:39:47
【问题描述】:

我需要有关我用来从 dwg 文件中的块中获取属性信息的数据提取程序的帮助。

我在网上获得了基本代码,我根据自己的需要进行了修改。不过,这部分是完全相同的。 (Link of the thread for the source)

步骤如下:

  1. 此代码在构建时生成一个 DLL 库,
  2. 然后我使用“NETLOAD”命令将其加载到 AutoCAD 2012 中;
  3. 之后我运行命令“ATT2CSV”(在此代码中定义),
  4. 这给了我输出文件。

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

这个互操作和 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...
    }
  }
}

提前致谢!

【问题讨论】:

    标签: c# attributes block extract autocad


    【解决方案1】:

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

    在 VB 中:

    'First get the current drawing path
    Dim currentpath =  doc.Name
    
    'Start the Function AttExt
    AttExt( currentpath , csvPathname )
    

    干杯, 阿兰

    【讨论】:

    • 非常感谢您的帮助;它完美无缺!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 2011-02-16
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多