zoukankan      html  css  js  c++  java
  • revit 碰撞检测相关

    Revit二次开发:由房间获取房间的墙

     

    之前用的方法是由房间边界构成的Solid,计算与该Solid相交的Element,然后判断是否为墙。相对来说这个方法比较通用,可以检索出房间的楼板、窗户等各种构件。

    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);
    }
    }

    只是找墙的话,其实用BoundarySegment.ElementId,就可以直接得到构成这个边界部分的元素(墙)。

    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);
    }
    }
    }

    •  碰撞检测:

      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)//遍历每一个元素
      {
      ids.Add(elem.Id);//将elem的Id添加到List中
      }
      select.SetElementIds(ids);
      trans.Commit();

      return Result.Succeeded;
      }
      }

      }

       

       

      筛选出和该元素相交的元素之BoundingBoxIntersectsFilter

      //假设元素为ee

      BoundingBoxXYZ box = ee.get_BoundingBox(doc.ActiveView);
      //创建outline,通过boundingboxintersect过滤器
      Outline myOutLn = new Outline(box.Min, box.Max);
      BoundingBoxIntersectsFilter boxee = new BoundingBoxIntersectsFilter(myOutLn);
      FilteredElementCollector collector = new FilteredElementCollector(doc);

      //过滤出相交元素,假设用到的是板类型

      IList<Element> elements = collector.OfClass(typeof(Floor)).WherePasses(boxee).ToElements();

  • 相关阅读:
    FFF NOJ 2073 裸KM算法
    FFF NOJ 2073 裸KM算法
    FFF NOJ 2073 裸KM算法
    【HDOJ】3242 List Operations
    【HDOJ】2319 Card Trick
    【HDOJ】1760 A New Tetris Game
    【HDOJ】1525 Euclid's Game
    【HDOJ】2217 Visit
    【HDOJ】2144 Evolution
    【HDOJ】1987 Decoding
  • 原文地址:https://www.cnblogs.com/liaocheng/p/11982488.html
Copyright © 2011-2022 走看看