Skip to content

Commit edea382

Browse files
authored
Merge pull request #163 from romangolev/dev
Make application compatible with Revit 2025
2 parents e9afe5d + 2070c2f commit edea382

File tree

16 files changed

+880
-598
lines changed

16 files changed

+880
-598
lines changed

.github/workflows/Workflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Workflow
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- '**'
@@ -16,4 +17,4 @@ jobs:
1617
- name: Checkout
1718
uses: actions/checkout@v1
1819
- name: Run Nuke Build
19-
run: ./.nuke/build.cmd --GitHubToken ${{ secrets.GITHUB_TOKEN }}
20+
run: ./.nuke/build.cmd --GitHubToken ${{ secrets.GITHUB_TOKEN }}

Installer/Installer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
const string projectName = "RevitPythonShell";
1313
const string outputName = "RevitPythonShell";
1414
const string outputDir = "output";
15-
const string version = "2.0.2";
15+
const string version = "2.1.0";
1616

1717
var fileName = new StringBuilder().Append(outputName).Append("-").Append(version);
1818
var project = new Project

Installer/Installer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<PlatformTarget>x64</PlatformTarget>
66
<TargetFramework>net48</TargetFramework>
77
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
8+
<Configurations>Debug;Release</Configurations>
89
</PropertyGroup>
910
<PropertyGroup Condition="$(Configuration.Contains('Release'))">
1011
<Optimize>true</Optimize>

PythonConsoleControl/PythonConsole.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using ICSharpCode.AvalonEdit.Editing;
1515
using ICSharpCode.AvalonEdit.Document;
1616
using Style = Microsoft.Scripting.Hosting.Shell.Style;
17-
using System.Runtime.Remoting;
1817

1918
namespace PythonConsoleControl
2019
{
@@ -26,6 +25,28 @@ namespace PythonConsoleControl
2625
/// </summary>
2726
public class PythonConsole : IConsole, IDisposable
2827
{
28+
29+
Action<Action> commandDispatcher;
30+
public Action<Action> GetCommandDispatcherSafe()
31+
{
32+
if (commandDispatcher == null)
33+
{
34+
try
35+
{
36+
var languageContext = Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(commandLine.ScriptScope.Engine);
37+
var pythonContext = (IronPython.Runtime.PythonContext)languageContext;
38+
commandDispatcher = pythonContext.GetSetCommandDispatcher(null);
39+
pythonContext.GetSetCommandDispatcher(commandDispatcher);
40+
}
41+
catch (Exception ex)
42+
{
43+
Debug.WriteLine("Failed to get dispatcher: " + ex.Message);
44+
commandDispatcher = action => action(); // fallback dispatcher
45+
}
46+
}
47+
return commandDispatcher;
48+
}
49+
2950
bool allowFullAutocompletion = true;
3051
public bool AllowFullAutocompletion
3152
{
@@ -381,13 +402,35 @@ void ExecuteStatements()
381402
}
382403
else
383404
{
384-
ObjectHandle wrapexception = null;
385-
GetCommandDispatcher()(() => scriptSource.ExecuteAndWrap(commandLine.ScriptScope, out wrapexception));
386-
if (wrapexception != null)
405+
Exception capturedEx = null;
406+
var dispatcher = GetCommandDispatcherSafe();
407+
408+
ManualResetEventSlim done = new ManualResetEventSlim();
409+
410+
dispatcher(() =>
411+
{
412+
try
413+
{
414+
scriptSource.Execute(commandLine.ScriptScope);
415+
}
416+
catch (Exception ex)
417+
{
418+
capturedEx = ex;
419+
}
420+
finally
421+
{
422+
done.Set();
423+
}
424+
});
425+
426+
done.Wait();
427+
428+
if (capturedEx != null)
387429
{
388-
error = "Exception : " + wrapexception.Unwrap().ToString() + "\n";
430+
var eo = commandLine.ScriptScope.Engine.GetService<ExceptionOperations>();
431+
error = eo.FormatException(capturedEx) + Environment.NewLine;
389432
}
390-
}
433+
}
391434
}
392435
catch (ThreadAbortException tae)
393436
{

PythonConsoleControl/PythonTextEditor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ public void Write(string text)
7474

7575
public void Write(string text, bool allowSynchronous, bool moveToEnd)
7676
{
77-
//text = text.Replace("\r\r\n", "\r\n");
78-
text = text.Replace("\r\r\n", "\r");
79-
text = text.Replace("\r\n", "\r");
77+
text = text.Replace("\r\r\n", "\r\n"); // Normalize Windows-style newlines
78+
text = text.Replace("\r\n", "\n"); // Or "\r" if needed
79+
text = text.Replace("\0", ""); // Remove NUL characters
80+
8081
if (allowSynchronous)
8182
{
8283
if (moveToEnd)

0 commit comments

Comments
 (0)