Skip to content

Commit cc91205

Browse files
committed
Failed when running compilation
pipenv run pyrevit build labs pipenv run pyrevit build products Debug copy .\release\.pyrevitargs . --- refactor: update ScriptRuntimeConfigs properties for better encapsulation - Changed LogFilePath and SuppressOutput from fields to properties in ScriptRuntimeConfigs for improved encapsulation. - Updated PyRevitRunnerCommand to set these properties dynamically, enhancing flexibility and maintainability.
1 parent c6cf0af commit cc91205

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

dev/pyRevitLabs.PyRevit.Runtime/scriptruntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class ScriptRuntimeConfigs : IDisposable {
3232
public List<string> SearchPaths { get; set; }
3333
public List<string> Arguments { get; set; }
3434
public IDictionary<string, object> Variables { get; set; }
35-
public string LogFilePath;
36-
public bool SuppressOutput;
35+
public string LogFilePath { get; set; }
36+
public bool SuppressOutput { get; set; }
3737

3838
public object EventSender {
3939
get { return _eventSender; }

dev/pyRevitLoader/Source/PyRevitRunnerCommand.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33

44
using Autodesk.Revit.Attributes;
@@ -62,15 +62,28 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
6262
DebugMode = false,
6363
ConfigMode = false,
6464
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
7366
};
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+
}
7487

7588
var env = new EnvDictionary();
7689
var resultCode = ScriptExecutor.ExecuteScript(
@@ -186,10 +199,10 @@ private static void LogRunnerError(string logFilePath, Exception ex) {
186199
try {
187200
File.AppendAllText(logFilePath, ex.ToString());
188201
}
189-
catch (Exception ex) {
202+
catch (Exception exInner) {
190203
// Best-effort: do not throw while writing the runner error log.
191204
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)
193206
);
194207
}
195208
}

0 commit comments

Comments
 (0)