在 vs2008 C# 上工作,需要帮助连接 autocad 2010,我按照以下步骤连接,但它给了我一个错误。
我必须添加引用,所以我转到引用>>添加引用>>[COM TAB]>>Autocad 2010 类型库>>[OK]
我使用两个库:
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 时出错