1 回答

TA貢獻1852條經(jīng)驗 獲得超7個贊
您是否嘗試從 Excel 中運行代碼,并嘗試讓 Excel 打開 AutoCAD 來操作繪圖?我認為這行不通。您可以采用另一種方式,打開 AutoCAD,加載插件,然后通過 API 將 AutoCAD 中的信息提供給 Excel。AutoCAD API 需要運行 AutoCAD(或 ACCORECONSOLE,這是 AutoCAD 的命令行版本,但這需要一些額外的管道)才能對圖形文件執(zhí)行任何操作。如果是 AutoCAD,而不是 ACCORECONSOLE,則通常需要至少打開一張圖形(..DocumentManager.MdiActiveDocument)。然后,您可以使用文檔管理器打開其他文檔(假設(shè)您有權(quán)限這樣做)。
/// <summary>
/// Look through the Application's Document manager for a Document object with the given name. If found return it,
/// else open the drawing/Document and return it.
/// </summary>
/// <param name="name">The name to look for in the collection</param>
/// <returns>An AutoCAD Document object.</returns>
public static ACADApp.Document GetDocumentByName(string name)
{
try
{
foreach (ACADApp.Document doc in ACADApp.Application.DocumentManager)
{
if (doc.Database.Filename.ToUpper() == name.ToUpper() || doc.Name.ToUpper() == name.ToUpper())
{
return doc;
}
}
return ACADApp.Application.DocumentManager.Open(name);
}
catch (System.Exception ex)
{
TBExceptionManager.HandleException(name, ex);
return null;
}
}
- 1 回答
- 0 關(guān)注
- 160 瀏覽
添加回答
舉報