revit 碰撞检测相关

摘要:
Revit二次开发:由房间获取房间的墙之前用的方法是由房间边界构成的Solid,计算与该Solid相交的Element,然后判断是否为墙。相对来说这个方法比较通用,可以检索出房间的楼板、窗户等各种构件。=null){wallsOfRoom.Add;}}只是找墙的话,其实用BoundarySegment.ElementId,就可以直接得到构成这个边界部分的元素(墙)。
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();

免责声明:文章转载自《revit 碰撞检测相关》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇TeeChart 8.01 With Source在Delphi 7.0中的安装(转)golang学习笔记---reflect包下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Revit 二次开发 元素创建与修改练习

学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=11 实例练习一 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.UI; using A...

Revit导入lumion渲染

利用Revit导出DAE文件格式插件,可以将Revit模型导入到lumion中进行图片渲染和漫游动画的制作。 lumion中的效果果然比Revit中好得多,材质显示漂亮,编辑方便,图片渲染速度快,特别是漫游动画的制作,Revit中画漫游路径的方式根本没法跟lumion相比。 这地板可以以假乱真。 lumion强大的漫游功能,丰富的附加组件,绚丽的视...

revit添加族参数

打开一个族文件,并为族文件添加参数 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){try{UIApplication uiApp = commandData.Application;Autodesk.Revit....

Revit 二次开发 交互及UIAPI之TaskDialog

学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=13 TaskDialog任务对话框 任务对话框的控件 任务对话框 任务对话框执行结果 实例练习一 using System; using System.Collections.Generic; using System.Linq; using...