Delete Warning WorksharingFailures.DuplicateNamesChanged when syncronise

Delete Warning WorksharingFailures.DuplicateNamesChanged when syncronise

david_rock
Enthusiast Enthusiast
3,895 Views
2 Replies
Message 1 of 3

Delete Warning WorksharingFailures.DuplicateNamesChanged when syncronise

david_rock
Enthusiast
Enthusiast

Hello,

 

Does anyone know how I can apply and delete the error 'WorksharingFailures.DuplicateNamesChange' These elements' names were automatically changed to eliminate duplicates when synchronizing? I can only find this in a transaction, however I can't have an open transaction during syncronise.

 

Public Class DuplicateNamesChangedWarningSwallower
    Implements IFailuresPreprocessor
    Public Function PreprocessFailures(failuresAccessor As FailuresAccessor) As FailureProcessingResult Implements IFailuresPreprocessor.PreprocessFailures
        Dim failures As List(Of FailureMessageAccessor) = failuresAccessor.GetFailureMessages()
        For Each f As FailureMessageAccessor In failures
            Dim id As FailureDefinitionId = f.GetFailureDefinitionId()
            If BuiltInFailures.WorksharingFailures.DuplicateNamesChanged = id Then
                failuresAccessor.DeleteWarning(f)
            End If
        Next
        Return FailureProcessingResult.Continue
    End Function
End Class

 

 

Kind Regards

David

 

 

0 Likes
Accepted solutions (1)
3,896 Views
2 Replies
Replies (2)
Message 2 of 3

FAIR59
Advisor
Advisor
Accepted solution

At the start of your add-in subscribe to the FailuresProcessing event, and on closing the add-in unsubscribe.

 

the code from your warningswallower can be used in the event handler.

 

c# code:

 

    public class _Cmd : IExternalCommand
    {
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            Document document = revit.Application.ActiveUIDocument.Document;
            revit.Application.Application.FailuresProcessing += Application_FailuresProcessing;
            try
            {
                // Do your thing
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                TaskDialog.Show("catch", ex.ToString());
                return Result.Failed;
            }
            finally
            {
                revit.Application.Application.FailuresProcessing -= Application_FailuresProcessing;
            }
        }

        void Application_FailuresProcessing(object sender, Autodesk.Revit.DB.Events.FailuresProcessingEventArgs e)
        {
            FailuresAccessor fa = e.GetFailuresAccessor();
            IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
            failList = fa.GetFailureMessages(); // Inside event handler, get all warnings
            foreach (FailureMessageAccessor failure in failList)
            {

                // check FailureDefinitionIds against ones that you want to dismiss, FailureDefinitionId failID = failure.GetFailureDefinitionId();
                // prevent Revit from showing Unenclosed room warnings
                FailureDefinitionId failID = failure.GetFailureDefinitionId();
                if (failID == BuiltInFailures.WorksharingFailures.DuplicateNamesChanged)
                {
                    fa.DeleteWarning(failure);
                }
            }
        }
    }
Message 3 of 3

luisdelaparra
Participant
Participant

Does Anyone know if this can be done in Python?

I am saving all loadable Families of a Project to a specific Path. But when I save families with Warnings, the warning dialogue box appears. Therefore, I need to click (ok, Remove, etc) each time the Script is saving a family with warnings. 

This graph is part of a set used to monitor the project, the intention is to leave the graph work for 10 minutes until done. Having to be there and click is not convenient for my workflow. 

 

This Code creates the paths for the Families: In case they don't exist, and then saves each family from the project directly to that path. This Code was assembled taking ideas and parts from the community. Thanks!!!

 

 

 import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import binascii
clr.AddReference("DSCoreNodes")
import DSCore
from DSCore import *
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import errno
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog
from System.IO import FileInfo

doc = DocumentManager.Instance.CurrentDBDocument



fams = UnwrapElement(IN[0])
paths = IN[1]
familypath = IN[2]
report = []


if not os.path.exists(familypath):
    try:
        os.makedirs(familypath)
    except OSError as exc: # Guard against race condition
        if exc.errno != errno.EEXIST:
            raise
            
#Close all transactions            
trans = TransactionManager.Instance
trans.ForceCloseTransaction()
#unwrap the Dynamo elements
TransactionManager.Instance.EnsureInTransaction(doc)
#fams = map(UnwrapElement, fams)

for i in xrange(len(fams) 😞
    try:
        famDoc = doc.EditFamily(fams[i])
        famDoc.SaveAs(paths[i])
        famDoc.Close(False)
        error = "Success"
    except:
            error = "Most likely these files already exist"
    report.append(error)        
    
TransactionManager.Instance.TransactionTaskDone()

OUT = report