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

您的位置:網(wǎng)站首頁 > CAD新聞

用.Net獲取AutoCAD當(dāng)前執(zhí)行程序集路徑

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

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;
            //當(dāng)前執(zhí)行程序集完整路徑
            string File = Assembly.GetExecutingAssembly().Location;
            //執(zhí)行程序集所在目錄
            FileInfo assinfo = new FileInfo(File);
            string path = assinfo.DirectoryName;

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