我想看一级黄色大片_久久亚洲国产精品一区二区_久久精品免视看国产明星_91久久青青青国产免费

您的位置:網站首頁 > CAD新聞

用.Net獲取AutoCAD當前執行程序集路徑

時間:2010-01-23 23:48:01 來源:
在對AutoCAD進行二次開發過程中,有時會需要獲取當前程序集所在的路徑,以便通過相對路徑進行數據庫連接,避免打開不同的dwg文件后系統當前相對路徑被修改而造成的數據庫連接錯誤。以下的代碼實現了當前執行程序集路徑的獲取功能:

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

using System.IO;
using System.Reflection;

namespace PathTest
{
    public class Command2
    {
        [CommandMethod("PTHA")]
        public void AssemblyPath()
        {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            //當前執行程序集完整路徑
            string File = Assembly.GetExecutingAssembly().Location;
            //執行程序集所在目錄
            FileInfo assinfo = new FileInfo(File);
            string path = assinfo.DirectoryName;

            doc.Editor.WriteMessage(
              "n當前程序序集路徑: " + path
            );
        }
    }
}