Skip to content

Commit

Permalink
add some try catch (#3040)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkkirschner authored Feb 20, 2024
1 parent bf2f125 commit cde18b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/DynamoRevit/DynamoRevit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Ionic.Zip.xml" />
<EmbeddedResource Include="Resources\Category.Revit.svg" />
<EmbeddedResource Include="Resources\LayoutSpecs.json" />
<Content Include="Resources\logo_square_32x32.png" />
Expand Down
29 changes: 22 additions & 7 deletions src/DynamoRevit/Models/RevitDynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
Expand Down Expand Up @@ -443,9 +444,16 @@ private void SetupPythonEngine(PythonEngine engine)
{
if (engine != null)
{
(engine.OutputDataMarshaler as DataMarshaler).RegisterMarshaler((Element element) => element.ToDSType(true));
engine.EvaluationStarted += OnPythonEvalStart;
engine.EvaluationFinished += OnPythonEvalFinished;
try
{
(engine.OutputDataMarshaler as DataMarshaler).RegisterMarshaler((Element element) => element.ToDSType(true));
engine.EvaluationStarted += OnPythonEvalStart;
engine.EvaluationFinished += OnPythonEvalFinished;
}
catch(FileNotFoundException ex)
{
Logger.Log(ex);
}
}
}

Expand All @@ -455,11 +463,18 @@ private void SetupPythonEngine(PythonEngine engine)
/// <param name="engine"></param>
private void CleanUpPythonEngine(PythonEngine engine)
{
if (engine != null)
try
{
if (engine != null)
{
(engine.OutputDataMarshaler as DataMarshaler).UnregisterMarshalerOfType<Element>();
engine.EvaluationStarted -= OnPythonEvalStart;
engine.EvaluationFinished -= OnPythonEvalFinished;
}
}
catch (FileNotFoundException ex)
{
(engine.OutputDataMarshaler as DataMarshaler).UnregisterMarshalerOfType<Element>();
engine.EvaluationStarted -= OnPythonEvalStart;
engine.EvaluationFinished -= OnPythonEvalFinished;
Logger.Log(ex);
}
}

Expand Down

0 comments on commit cde18b5

Please sign in to comment.