gpt4 book ai didi

c# - 如何连接 C# 与 AUTOCAD 2010

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:28 24 4
gpt4 key购买 nike

在 vs2008 C# 上工作,需要帮​​助连接 autocad 2010,我按照以下步骤进行连接,但它给了我一个错误。

我必须添加一个引用,所以我转到引用>>添加引用>>[COM TAB]>>Autocad 2010 类型库>>[确定]

我使用两个库:

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

然后我使用以下代码连接 AutoCAD 2010:

namespace Sample_CSharp_Acad_connect
{


class Program
{
private static IAcadApplication oAcadApp = null;
private static string sAcadID = "AutoCAD.Application.18";

static void Main()
{
try //get a running AutoCAD instance if avaialbale
{
oAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(sAcadID);
}
catch(Exception) //none found so start a new instance
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
oAcadApp = (IAcadApplication)System.Activator.CreateInstance(AcadProg);
}
if (oAcadApp != null)
{
oAcadApp.Visible = true; //could leave this false to hide Acad from the user
//do whatever with Acad
//oAcadApp.Quit();
}
}
}

错误消息:获取组件 CLSID 的对象类 COM 时出错 enter image description here

最佳答案

COM?不要这样做。

AutoCAD 有一个 .NET API。参见 http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112从 Autodesk 获取资源。另请参阅此处的 wiki 以获取更多信息和大量链接:https://stackoverflow.com/tags/autocad/info

关于c# - 如何连接 C# 与 AUTOCAD 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11397205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com