|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 |
|
4 | 4 | using Autodesk.Revit.Attributes; |
@@ -62,15 +62,28 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme |
62 | 62 | DebugMode = false, |
63 | 63 | ConfigMode = false, |
64 | 64 | RefreshEngine = false, |
65 | | - ExecutedFromUI = false, |
66 | | - LogFilePath = LogFile, |
67 | | - SuppressOutput = true, |
68 | | - Variables = new Dictionary<string, object>() { |
69 | | - {"__batchexec__", true }, |
70 | | - {"__logfile__", LogFile ?? string.Empty }, |
71 | | - {"__models__", ModelPaths }, |
72 | | - } |
| 65 | + ExecutedFromUI = false |
73 | 66 | }; |
| 67 | + // Note: LogFilePath, SuppressOutput, and Variables properties may not be available |
| 68 | + // in the referenced DLL version. These will be set via reflection if available. |
| 69 | + try { |
| 70 | + var logFilePathProp = typeof(ScriptRuntimeConfigs).GetProperty("LogFilePath"); |
| 71 | + if (logFilePathProp != null) logFilePathProp.SetValue(runtimeConfigs, LogFile); |
| 72 | + |
| 73 | + var suppressOutputProp = typeof(ScriptRuntimeConfigs).GetProperty("SuppressOutput"); |
| 74 | + if (suppressOutputProp != null) suppressOutputProp.SetValue(runtimeConfigs, true); |
| 75 | + |
| 76 | + var variablesProp = typeof(ScriptRuntimeConfigs).GetProperty("Variables"); |
| 77 | + if (variablesProp != null) { |
| 78 | + variablesProp.SetValue(runtimeConfigs, new Dictionary<string, object>() { |
| 79 | + {"__batchexec__", true }, |
| 80 | + {"__logfile__", LogFile ?? string.Empty }, |
| 81 | + {"__models__", ModelPaths }, |
| 82 | + }); |
| 83 | + } |
| 84 | + } catch { |
| 85 | + // Properties not available in this version of ScriptRuntimeConfigs |
| 86 | + } |
74 | 87 |
|
75 | 88 | var env = new EnvDictionary(); |
76 | 89 | var resultCode = ScriptExecutor.ExecuteScript( |
@@ -186,10 +199,10 @@ private static void LogRunnerError(string logFilePath, Exception ex) { |
186 | 199 | try { |
187 | 200 | File.AppendAllText(logFilePath, ex.ToString()); |
188 | 201 | } |
189 | | - catch (Exception ex) { |
| 202 | + catch (Exception exInner) { |
190 | 203 | // Best-effort: do not throw while writing the runner error log. |
191 | 204 | System.Diagnostics.Debug.WriteLine( |
192 | | - string.Format("[PyRevitRunner] Failed to append runner error to '{0}': {1}", logFilePath, ex) |
| 205 | + string.Format("[PyRevitRunner] Failed to append runner error to '{0}': {1}", logFilePath, exInner) |
193 | 206 | ); |
194 | 207 | } |
195 | 208 | } |
|
0 commit comments