Skip to content

Commit

Permalink
fix event when use outside doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Jun 30, 2022
1 parent 77f983d commit afe54cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions AddInManager/Model/RevitEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace RevitAddinManager.Model
public class RevitEvent : IExternalEventHandler
{
private Action DoAction;
private Document Doc;
private readonly ExternalEvent ExEvent;
private bool SkipFailures;
private string TransactionName;
Expand All @@ -26,11 +25,10 @@ public RevitEvent()
/// <param name="doc">document</param>
/// <param name="transactionName">transaction name</param>
/// <param name="withTrans">is transaction</param>
public void Run(Action doAction, bool skipFailures, Document doc = null, string transactionName = null, bool withTrans = true)
public void Run(Action doAction, bool skipFailures, string transactionName = null, bool withTrans = true)
{
this.DoAction = doAction;
this.SkipFailures = skipFailures;
this.Doc = doc;
WithTransaction = withTrans;
ExEvent.Raise();
this.TransactionName = transactionName;
Expand All @@ -42,13 +40,13 @@ public void Execute(UIApplication app)
{
if (DoAction != null)
{
if (Doc == null) Doc = app.ActiveUIDocument.Document;

if (SkipFailures)
app.Application.FailuresProcessing += Application_FailuresProcessing;

if (WithTransaction)
{
using (Transaction t = new Transaction(Doc, TransactionName ?? "RevitEvent"))
using (Transaction t = new Transaction(app.ActiveUIDocument.Document, TransactionName ?? "RevitEvent"))
{
t.Start();
DoAction();
Expand Down
2 changes: 1 addition & 1 deletion AddInManager/ViewModel/AddInManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void ExecuteAddinCommandClick()
if (result > 0)
{
App.FrmAddInManager.Close();
RevitEvent.Run(Execute, false, null, null, false);
RevitEvent.Run(Execute, false, null, false);
}
}
}
Expand Down

0 comments on commit afe54cc

Please sign in to comment.