Disable the error highlighted elements are joined but do not intersect

Disable the error highlighted elements are joined but do not intersect

Anonymous
Not applicable
2,287 Views
3 Replies
Message 1 of 4

Disable the error highlighted elements are joined but do not intersect

Anonymous
Not applicable

When I want to join wall and structural framing it shows error that highlighted elements are joined but do not intersect. What this error mean?

 

And if I want to disable this error and create own taskdialog box and display my error how I do this?

 

 

this is my code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace JoinGeometry
{
[Transaction(TransactionMode.Manual)]
class WBjoin
{
bool check;
public Result Execute(ExternalCommandData commandData)
{
UIApplication uiApp = commandData.Application;
// UIDocument uiDoc = uiApp.ActiveUIDocument;
// Application app = uiApp.Application;
// Document doc = uiDoc.Document;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

 

//--get walls on the active view-----------

FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));


foreach (Wall w in collWalls)
{
FilteredElementCollector wallbeam = new FilteredElementCollector(doc, doc.ActiveView.Id);

wallbeam.OfClass(typeof(FamilyInstance));
wallbeam.OfCategory(BuiltInCategory.OST_StructuralFraming);


BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =
new BoundingBoxIntersectsFilter(outline);
wallbeam.WherePasses(bbfilter);
foreach (FamilyInstance bem in wallbeam)
{
using (Transaction t = new Transaction(doc, "Join All Walls/beam"))
{
t.Start();
try
{

check = JoinGeometryUtils.AreElementsJoined(doc, w, bem);
if (check == true)
{

}
else
{
JoinGeometryUtils.JoinGeometry(doc, w, bem);
}
}
catch
{
TaskDialog.Show("revit", "cannot joined");
}

t.Commit();
}

}

}


return Result.Succeeded;
}
}
}

0 Likes
2,288 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Message 3 of 4

Anonymous
Not applicable

I want to join wall and column but there is problem in join. The two element bounding box is joined but not the actual elements are interesect,if I join that element is shows error. I want make code such a way that it check bounding box and also check the actual element is intersect or not. If both condion is statisfy then it join the element.How I do this?

 

I using the previous posted code.

0 Likes
Message 4 of 4

Mustafa.Salaheldin
Collaborator
Collaborator

Please try the following code and tell me if it satisfies your needs:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace JoinGeometry
{
    [Transaction(TransactionMode.Manual)]
    class WBjoin
    {
        bool check;
        public Result Execute(ExternalCommandData commandData)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uidoc = uiApp.ActiveUIDocument;
            Document doc = uidoc.Document;



            //--get walls on the active view-----------

            FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
            collWalls.OfClass(typeof(Wall));


            foreach (Wall w in collWalls)
            {
                FilteredElementCollector wallbeam = new FilteredElementCollector(doc, doc.ActiveView.Id);

                wallbeam.OfClass(typeof(FamilyInstance));
                wallbeam.OfCategory(BuiltInCategory.OST_StructuralFraming);


                BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
                Outline outline = new Outline(bb.Min, bb.Max);
                BoundingBoxIntersectsFilter bbfilter = new BoundingBoxIntersectsFilter(outline);
                wallbeam.WherePasses(bbfilter);

                foreach (FamilyInstance bem in wallbeam)
                {
                    using (Transaction t = new Transaction(doc, "Join All Walls/beam"))
                    {
                        t.Start();
                        FailureHandlingOptions options = t.GetFailureHandlingOptions();
                        WarningDiscard preproccessor = new WarningDiscard();
                        options.SetFailuresPreprocessor(preproccessor);
                        t.SetFailureHandlingOptions(options);

                        try
                        {

                            check = JoinGeometryUtils.AreElementsJoined(doc, w, bem);
                            if (check == true)
                            {

                            }
                            else
                            {
                                JoinGeometryUtils.JoinGeometry(doc, w, bem);
                            }
                        }
                        catch
                        {
                            TaskDialog.Show("revit", "cannot joined");
                        }

                        t.Commit();
                    }

                }

            }
            return Result.Succeeded;
        }

        public class WarningDiscard : IFailuresPreprocessor
        {
            FailureProcessingResult
              IFailuresPreprocessor.PreprocessFailures(FailuresAccessor failuresAccessor)
            {
                String transactionName = failuresAccessor.GetTransactionName();

                IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();

                if (fmas.Count == 0)
                {
                    return FailureProcessingResult.Continue;
                }

                bool isResolved = false;

                foreach (FailureMessageAccessor fma in fmas)
                {
                    if (fma.HasResolutions())
                    {
                        failuresAccessor.ResolveFailure(fma);
                        isResolved = true;
                    }
                }

                if (isResolved)
                {
                    return FailureProcessingResult.ProceedWithCommit;
                }

                return FailureProcessingResult.Continue;
            }
        }

    }
}

If it is what you want please mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn