第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Autocad .Net 集成 - 從 Excel 調(diào)用簡單函數(shù)時成功編譯 DLL 錯誤

Autocad .Net 集成 - 從 Excel 調(diào)用簡單函數(shù)時成功編譯 DLL 錯誤

C#
慕森卡 2023-08-13 15:59:34
我正在處理一個需要在 Excel 中集成 Autocad 的項目。我編譯了一個 DLL,并在 Excel 中成功引用,但調(diào)用一個簡單函數(shù)失敗。                                         COM接口沒有問題;該項目已勾選這些,我可以成功地從 Excel 調(diào)用一個簡單的“hello world”測試函數(shù)。我還擁有 C# 項目中所有正確的引用。多余的參考資料是后續(xù)工作所需要的。該函數(shù)在這一行失敗:var acDocMgr = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;如果無論 Autocad 應(yīng)用程序是否打開都失敗。請幫忙。using System.Collections.Generic;using System.Runtime.InteropServices;using System.Linq;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.Runtime;using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;using Autodesk.AutoCAD.ApplicationServices;[assembly: CommandClass(typeof(AutocadHandler.MyCommands))]namespace AutocadHandler{    [ClassInterface(ClassInterfaceType.AutoDual)]    public class MyCommands    {        public static void TestFunction()        {                                   string strFileName = "C:\\Users\\CORE I7\\Documents\\Drawing2XLS.dwg";            var acDocMgr = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;            acDocMgr.Open(strFileName, false);            acDocMgr.MdiActiveDocument.Editor.WriteMessage("Hello Excel");        }    }}Excel 返回的錯誤是:運行時錯誤'-2146233036 (80131534)':自動化錯誤
查看完整描述

1 回答

?
慕姐4208626

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;

        }

    }


查看完整回答
反對 回復(fù) 2023-08-13
  • 1 回答
  • 0 關(guān)注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號