protected override void OnEvaluationCompleted(object sender, EventArgs e) { //Cleanup Delegate Action cleanup = delegate { //TODO: perhaps this should occur inside of ResetRuns in the event that // there is nothing to be deleted? //Initialize a transaction (if one hasn't been aleady) TransactionManager.Instance.EnsureInTransaction( DocumentManager.Instance.CurrentUIDocument.Document); //Reset all elements IEnumerable <RevitTransactionNode> query = dynSettings.Controller.DynamoModel.AllNodes.OfType <RevitTransactionNode>(); foreach (RevitTransactionNode element in query) { element.ResetRuns(); } ////// /* FOR NON-DEBUG RUNS, THIS IS THE ACTUAL END POINT FOR DYNAMO TRANSACTION */ ////// //Close global transaction. TransactionManager.Instance.TransactionTaskDone(); }; //Rename Delegate Action rename = delegate { TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); foreach (var kvp in ElementNameStore) { //find the element and rename it Element el; if (dynUtils.TryGetElement(kvp.Key, out el)) { //if the element is not stored with a unique name //add a unique suffix to it try { if (el is ReferencePlane) { var rp = el as ReferencePlane; rp.Name = kvp.Value; } } catch (Exception) { if (el is ReferencePlane) { var rp = el as ReferencePlane; rp.Name = kvp.Value + "_" + Guid.NewGuid(); } } } } ElementNameStore.Clear(); TransactionManager.Instance.TransactionTaskDone(); }; cleanup(); rename(); TransactionManager.Instance.ForceCloseTransaction(); base.OnEvaluationCompleted(sender, e); }
protected override void OnEvaluationCompleted(object sender, EventArgs e) { base.OnEvaluationCompleted(sender, e); //Cleanup Delegate Action cleanup = delegate { //TODO: perhaps this should occur inside of ResetRuns in the event that // there is nothing to be deleted? InitTransaction(); //Initialize a transaction (if one hasn't been aleady) //Reset all elements var query = dynSettings.Controller.DynamoModel.AllNodes .OfType <RevitTransactionNode>(); foreach (RevitTransactionNode element in query) { element.ResetRuns(); } ////// /* FOR NON-DEBUG RUNS, THIS IS THE ACTUAL END POINT FOR DYNAMO TRANSACTION */ ////// EndTransaction(); //Close global transaction. }; //Rename Delegate Action rename = delegate { InitTransaction(); foreach (var kvp in ElementNameStore) { //find the element and rename it Element el = null; if (dynUtils.TryGetElement(kvp.Key, out el)) { //if the element is not stored with a unique name //add a unique suffix to it try { if (el is Autodesk.Revit.DB.ReferencePlane) { var rp = el as Autodesk.Revit.DB.ReferencePlane; rp.Name = kvp.Value; } } catch (Exception ex) { if (el is Autodesk.Revit.DB.ReferencePlane) { var rp = el as Autodesk.Revit.DB.ReferencePlane; rp.Name = kvp.Value + "_" + Guid.NewGuid(); } } } } ElementNameStore.Clear(); EndTransaction(); }; //If we're in a debug run or not already in the idle thread, then run the Cleanup Delegate //from the idle thread. Otherwise, just run it in this thread. if (dynSettings.Controller.DynamoViewModel.RunInDebug || !InIdleThread && !IsTestMode) { IdlePromise.ExecuteOnIdle(cleanup, false); IdlePromise.ExecuteOnIdle(rename, false); } else { cleanup(); rename(); } }