Revit开发里有一个ReferenceIntersector 类,
通过这个类可以找到某一条射线方向上的所有
Element的Reference
这个类有四种构造函数
Name | Description | |
---|---|---|
ReferenceIntersector(View3D) |
Constructs a ReferenceIntersector which is set to return intersections from all elements and representing all reference target types.
| |
ReferenceIntersector(ElementFilter, FindReferenceTarget, View3D) |
Constructs a ReferenceIntersector which is set to return intersections from any element which passes an input filter.
| |
ReferenceIntersector(ElementId, FindReferenceTarget, View3D) |
Constructs a ReferenceIntersector which is set to return intersections from a single target element only.
| |
ReferenceIntersector(ICollection<(Of <<'(ElementId>)>>), FindReferenceTarget, View3D) |
Constructs a ReferenceIntersector which is set to return intersections from any of a set of target elements.
|
无论哪一种都是需要一个3D视图
ElementFilter是查找的过滤条件
也可以通过ElementId 和Icollection<ElementID> 来直接设置查找对象
还可以通过
FindReferenceTarget
来设置目标类型
查找的时候需要调用Find 函数,它需要传入一个点和一个方向来确定一个射线
这个函数会返回一个
IList<ReferenceWithContext>这里包含了说有找到的Reference
下面是一个用射线法找到和管道相交的墙的例子
XYZ p1 = pline.GetEndPoint(0);
XYZ p2 = pline.GetEndPoint(1);
XYZ dir = (p2 - p1).Normalize();
double length = pline.Length;
ElementClassFilter wallFilter = new ElementClassFilter(typeof(Wall));
ReferenceIntersector rinter = new ReferenceIntersector(wallFilter,FindReferenceTarget.Element,v);
IList<ReferenceWithContext> rwc = rinter.Find(p1, dir);
int i = 0;
foreach (ReferenceWithContext r in rwc)
{
if (r.Proximity < length)
i++;
}
TaskDialog.Show("info", "墙的数量为:" + i.ToString());
博主会经常更新一些技术文章,请大家多多关注,
源码下载请加qq群480950299