本帖最后由 smartplot 于 2025-6-9 09:38 编辑

如题,我想获取目录用于通过反射调用com,请大家给看一下还有更简洁稳定的办法吗?

  1.       public static string? GetCADInstallDirectory()
  2.         {
  3.             // 获取 CAD 主程序路径
  4.             string executablePath = System.Reflection.Assembly.GetAssembly(typeof(Autodesk.AutoCAD.ApplicationServices.Application)).Location;
  5.             System.IO.FileInfo fileInfo = new System.IO.FileInfo(executablePath);
  6.             return fileInfo.Directory?.FullName;
  7.         }
复制代码




网友答:
箭头_Row 发表于 2025-6-21 00:11
  1. // 获取acad.exe完整路径
  2. acadPath =  System.Environment.GetCommandLineArgs()[0]; // 直接使用命令行参数获取acad.exe的完整路径
复制代码


网友答: 本帖最后由 你有种再说一遍 于 2025-6-9 19:39 编辑

为什么要反射com?
要获取全部cad路径?那么为什么不遍历注册表?
要获取当前进程exe路径?那么为什么通过c#各种获取路径的文章.

https://www.cnblogs.com/JJBox/p/10214582.html

https://www.cnblogs.com/JJBox/p/11381254.html



网友答:
你有种再说一遍 发表于 2025-6-9 18:28
为什么要反射com?
要获取全部cad路径?那么为什么不遍历注册表?
要获取当前进程exe路径?那么为什么通过c# ...

谢谢,这样简单多了

网友答: 你都有Autodesk.AutoCAD.ApplicationServices.Application了,那直接就拿他上面的com对象就可以开始反射了,还获取路径干什么

网友答: 获取安装目录
IO.Path.GetDirectoryName(Application.DocumentManager.MdiActiveDocument.GetType.Assembly.Location)

获取acad.exe完整路径
IO.Path.Combine(IO.Path.GetDirectoryName(Application.DocumentManager.MdiActiveDocument.GetType.Assembly.Location), "acad.exe")

网友答:
guohq 发表于 2025-6-16 23:17
获取安装目录
IO.Path.GetDirectoryName(Application.DocumentManager.MdiActiveDocument.GetType.Assembl ...

  1.   //获取安装目录
  2.   var path = Path.GetDirectoryName(Acaop.DocumentManager.MdiActiveDocument.GetType().Assembly.Location);
  3.   path.Print();
  4.   //获取acad.exe完整路径
  5.   path = Path.Combine(path, "acad.exe");
  6.   path.Print();


网友答: process.getcurprocess


网友答: path = Environment.GetCommandLineArgs()[0]; // 直接使用命令行参数获取acad.exe的完整路径
  • 上一篇:cad.net 我发现了一个大宝贝
  • 下一篇:没有了