工作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