Browse Source

xls:uiless Revit启动调整1.0

xulisong 5 years ago
parent
commit
18b7a480e3

BIN
JBIM/Dlls/RevitAddInUtility.dll


+ 3 - 0
JBIM/ExportStart/ExportStart.csproj

@@ -43,9 +43,11 @@
   <ItemGroup>
     <Reference Include="RevitAddInUtility">
       <HintPath>..\Dlls\RevitAddInUtility.dll</HintPath>
+      <Private>False</Private>
     </Reference>
     <Reference Include="RevitAPI">
       <HintPath>..\Dlls\RevitAPI.dll</HintPath>
+      <Private>False</Private>
     </Reference>
     <Reference Include="RevitNET">
       <HintPath>..\Dlls\RevitNET.dll</HintPath>
@@ -68,6 +70,7 @@
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RevitCoreContext.cs" />
+    <Compile Include="RevitUtils.cs" />
     <Compile Include="RevitVisionUtil.cs" />
   </ItemGroup>
   <ItemGroup>

+ 5 - 11
JBIM/ExportStart/RevitCoreContext.cs

@@ -7,14 +7,10 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Net.Mime;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
 using Autodesk.Revit;
 using Autodesk.Revit.ApplicationServices;
 using Autodesk.Revit.DB;
-using Autodesk.RevitAddIns;
 
 namespace ExportStart
 {
@@ -22,7 +18,7 @@ namespace ExportStart
     {
         // 此路径为动态反射搜索路径 、 此路径可为任意路径(只要路径下有RevitNET 所需依赖项即可,完整依赖项可在 Naviswork 2016 下面找到)
 
-        static readonly string[] Searchs = RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Name == "Revit 2017").Select(x => x.InstallLocation).ToArray();
+        private static readonly string[] Searchs = RevitUtils.GetSearchPath().ToArray();//new string[] { RevitUtils.GetRevitDllPath() };
 
         static readonly object lockobj = new object();
 
@@ -78,7 +74,7 @@ namespace ExportStart
         {
             var path = new[] { Environment.GetEnvironmentVariable("PATH") ?? string.Empty };
             //加在最前面,
-            var newPath = string.Join(System.IO.Path.PathSeparator.ToString(), paths.Concat(path));
+            var newPath = string.Join(Path.PathSeparator.ToString(), paths.Concat(path));
 
             Environment.SetEnvironmentVariable("PATH", newPath);
         }
@@ -86,15 +82,13 @@ namespace ExportStart
         private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
         {
             var assemblyName = new AssemblyName(args.Name);
-
             foreach (var item in Searchs)
             {
-                var file = string.Format("{0}.dll", System.IO.Path.Combine(item, assemblyName.Name));
-
+                var file = string.Format("{0}.dll", Path.Combine(item, assemblyName.Name));
                 if (File.Exists(file))
                 {
-                    NeedAssemblys.Add(assemblyName.Name);
-                    return Assembly.LoadFile(file);
+                    //NeedAssemblys.Add(assemblyName.Name);
+                    return Assembly.LoadFrom(file);
                 }
             }
 

+ 53 - 0
JBIM/ExportStart/RevitUtils.cs

@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:RevitUtils
+ * 作者:xulisong
+ * 创建时间: 2019/7/29 9:08:18
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.RevitAddIns;
+
+namespace ExportStart
+{
+    public class RevitUtils
+    {
+        /// <summary>
+        /// 获取Revit搜索dll路径
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetSearchPath()
+        {
+#if DEBUG
+         return   RevitProductUtility.GetAllInstalledRevitProducts().Where(t => t.Name == "Revit 2017").Select(x => x.InstallLocation).ToList();
+#else
+         return new List<string>(){GetRevitDllPath()};
+#endif
+        }
+        #region dll路径管理
+        /// <summary>
+        /// 获取RevitDll,所在目录
+        /// </summary>
+        /// <returns></returns>
+        public static string GetRevitDllPath()
+        {
+            if (!string.IsNullOrWhiteSpace(m_RevitDllPath))
+            {
+                return m_RevitDllPath;
+            }
+            return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\RevitDlls");
+        }
+
+        private static string m_RevitDllPath;
+        public static void SetRevitDllPath(string path)
+        {
+            m_RevitDllPath = path;
+        } 
+        #endregion
+    }
+}