工作VS2008 C#,需要帮助连接到autocad 2010,我按照以下步骤连接,但它给了我一个错误。如何连接C#与ACAD 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();
}
}
}
错误消息:错误地让对象类COM组件为CLSID
你得到了什么确切的错误? – 2012-07-09 14:42:41
FrédéricHamidi感谢您的回复,获取组件CLSID的对象类COM出错 – shamim 2012-07-09 14:51:38
看起来像AutoCAD类型库没有正确注册。你能否在'Program Files \ Common Files \ Autodesk Shared \ acax18enu.tlb'(或者你的等效本地化版本)上运行'regsrv32'? – 2012-07-09 15:11:36