Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The beam system creation is overlapping with family elements.

0 REPLIES 0
Reply
Message 1 of 1
praveen.cMXB2H
86 Views, 0 Replies

The beam system creation is overlapping with family elements.

I have developed a Revit add-in that creates beam systems for selected walls. The beam system is being created properly; however, it overlaps with any family elements placed on the wall. I want the beam system to avoid overlapping with family elements.
 
1.Required formatpraveencMXB2H_2-1730982733222.png

 

 

2. Achieved format
praveencMXB2H_3-1730982742665.png

 

The beam system created is overlapping with the elements that exist on the wall.
 
 
3.Source Code:
 
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;

namespace hello
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class clhello : IExternalCommand
    {
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;

            try
            {
                Reference wallRef = uiDoc.Selection.PickObject(ObjectType.Element, new WallSelectionFilter(), "Select a wall.");
                Wall selectedWall = doc.GetElement(wallRef.ElementId) as Wall;
                if (selectedWall == null)
                {
                    TaskDialog.Show("Error", "Selected element is not a wall.");
                    return Result.Failed;
                }

             
                Reference faceRef = uiDoc.Selection.PickObject(ObjectType.Face, "Select a face on the wall for the beam system.");
                GeometryObject geomObj = selectedWall.GetGeometryObjectFromReference(faceRef);
                Face selectedFace = geomObj as Face;
                if (selectedFace == null)
                {
                    TaskDialog.Show("Error", "Selected face is invalid.");
                    return Result.Failed;
                }

                BoundingBoxXYZ wallBoundingBox = selectedWall.get_BoundingBox(null);

                List<CurveLoop> exclusionRegions = new List<CurveLoop>();

                using (Transaction t = new Transaction(doc, "Create Beam Systems on Wall Face"))
                {
                    t.Start();
                    List<List<Curve>> exclusionCurvesL = new List<List<Curve>>();
                    List<Curve> boundaryCurves = new List<Curve>();
                    foreach (Edge edge in selectedFace.EdgeLoops.get_Item(0))
                    {
                        Curve edgeCurve = edge.AsCurve();
                        bool isExcluded = false;

                        foreach (CurveLoop exclusionRegion in exclusionRegions)
                        {
                            foreach (Curve exclusionCurve in exclusionRegion)
                            {
                                if (edgeCurve.Intersect(exclusionCurve) == SetComparisonResult.Overlap)
                                {
                                    isExcluded = true;
                                    break;
                                }
                            }
                            if (isExcluded) break;
                        }

                        if (!isExcluded)
                        {
                            boundaryCurves.Add(edgeCurve);
                        }

                    }

                    UV midpointUV = new UV(0.5, 0.5);
                    XYZ originPoint = selectedFace.Evaluate(midpointUV);
                    XYZ faceNormal = selectedFace.ComputeNormal(midpointUV);
                    XYZ horizontalBeamDirection = faceNormal.CrossProduct(XYZ.BasisZ);
                    XYZ verticalBeamDirection = faceNormal.CrossProduct(horizontalBeamDirection);
                    Plane facePlane = Plane.CreateByNormalAndOrigin(faceNormal, originPoint);
                    SketchPlane sketchPlane = SketchPlane.Create(doc, facePlane);
                 
                    BeamSystem horizontalBeamSystem = BeamSystem.Create(doc, boundaryCurves, sketchPlane, horizontalBeamDirection, false);
                    BeamSystem verticalBeamSystem = BeamSystem.Create(doc, boundaryCurves, sketchPlane, verticalBeamDirection, false);

                    t.Commit();
                    TaskDialog.Show("Success", "Horizontal and vertical beam systems created successfully, avoiding doors and windows on the wall face.");
                }

                return Result.Succeeded;
            }
            catch (OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }

     
        private class WallSelectionFilter : ISelectionFilter
        {
            public bool AllowElement(Element elem)
            {
                return elem is Wall;
            }

            public bool AllowReference(Reference reference, XYZ position)
            {
                return false;
            }
        }

    }
}
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report