revit related collision detection

Revit secondary development: acquisition by the wall of the room the room

 

The method used was previously made of room boundaries Solid calculated intersecting the Solid Element, and determines whether the wall. This method is relatively common, the various components can retrieve the room floor, windows and the like.

SpatialElementBoundaryOptions se=new SpatialElementBoundaryOptions();
se.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
SpatialElementGeometryCalculator calculator =new SpatialElementGeometryCalculator(document,se);
Solid solid = calculator.CalculateSpatialElementGeometry(room)?.GetGeometry();
var list = new FilteredElementCollector(document).WhereElementIsNotElementType().
WherePasses(new ElementIntersectsSolidFilter(solid)).ToList();

foreach (var element in list)
{
Wall wall=element as Wall;
if (wall!=null)
{
wallsOfRoom.Add(wall);
}
}

 

Just look for the wall, in fact, with BoundarySegment.ElementId, you can directly get elements (walls) constitute a part of this boundary.

 

IList<IList<BoundarySegment>> loops = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

foreach (IList<BoundarySegment> loop in loops)

{
foreach (BoundarySegment segment in loop)
{
Wall wall =document.GetElement(segment.ElementId) as Wall;
if (wall != null)
{
wallsOfRoom.Add(wall);
}
}
}

  •  Impact checking:

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

    using Autodesk.Revit.UI;
    using Autodesk.Revit.Attributes;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI.Selection;//类Selection使用

    namespace Collision
    {
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
    UIDocument uiDoc = commandData.Application.ActiveUIDocument;
    Document doc = uiDoc.Document;
    Transaction trans = new Transaction(doc,"Excomm");
    trans.Start();

    Selection select = uiDoc.Selection;
    Reference r = select.PickObject(ObjectType.Element, "选择需要检查的墙");
    Element column = doc.GetElement(r);
    FilteredElementCollector collect = new FilteredElementCollector(doc);

    //ElementIntersectionFilter冲突检查
    ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column,false);
    collect.WherePasses(iFilter);
    List<ElementId> excludes = new List<ElementId>();
    excludes.Add(column.Id);
    collect.Excluding(excludes);
    List<ElementId> ids = new List<ElementId>();
    select.SetElementIds(ids);{


    foreach (Element elem in collect) // through each element

    ids.Add (elem.Id); // add to the List of elem Id
    }
    select.SetElementIds (IDS);
    trans.Commit ();

    return Result.Succeeded;
    }
    }

    }

     

Guess you like

Origin www.cnblogs.com/liaocheng/p/11982488.html