博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Revit API射线法读取空间中相交的元素
阅读量:6856 次
发布时间:2019-06-26

本文共 2161 字,大约阅读时间需要 7 分钟。

Revit API提供根据射线来寻找经过的元素。方法是固定模式,没什么好说。
关键代码:
doc.FindReferencesWithContextByDirection(ptStart, (ptEnd - ptStart), view3d)
//
射线法寻找穿过的对象
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public 
class FindSupporting : IExternalCommand
{
    
public Result Execute(ExternalCommandData commandData, 
ref 
string messages, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Transaction trans = 
new Transaction(doc, 
"
ExComm
");
        trans.Start();
        Selection sel = app.ActiveUIDocument.Selection;
        
//
Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a beam");
        
//
FamilyInstance beam = doc.GetElement(ref1) as FamilyInstance;
        Reference ref1 = sel.PickObject(ObjectType.Element, 
"
Please pick a duct
");
        Duct duct = doc.GetElement(ref1) 
as Duct;
        
//
Read the beam's location line
        
//
LocationCurve lc = beam.Location as LocationCurve;
        LocationCurve lc = duct.Location 
as LocationCurve;
        Curve curve = lc.Curve;
        
//
取得线端点的方法
        XYZ ptStart = curve.get_EndPoint(
0);
        XYZ ptEnd = curve.get_EndPoint(
1);
        
//
move the two point a little bit lower, so the ray can go through the wall
        XYZ offset = 
new XYZ(
0
0
0.01);
//
向量偏移的方法,这里向下偏移。
        ptStart = ptStart - offset;
        ptEnd = ptEnd - offset;
        View3D view3d = 
null;
        view3d = doc.ActiveView 
as View3D;
        
if (view3d == 
null)
        {
            TaskDialog.Show(
"
3D view
"
"
current view should be 3D view
");
            
return Result.Failed;
        }
        
double beamLen = curve.Length;
        
//
终点-起点就是线的方向。这里是射线法的关键代码。必须在三维视图下。
        IList<ReferenceWithContext> references = doc.FindReferencesWithContextByDirection(ptStart, (ptEnd - ptStart), view3d);
        
//
ElementSet wallSet = app.Application.Create.NewElementSet();
        sel.Elements.Clear();
        
double tolerate = 
0.00001;
        
foreach (ReferenceWithContext reference 
in references)
        {
            Reference ref2 = reference.GetReference();
//
取得引用
            ElementId id = ref2.ElementId;
            Element elem = doc.get_Element(id);
            
if (elem 
is Wall)
            {
                
if (reference.Proximity < (beamLen + tolerate))
//
Proximity接近,即与射线原点的距离。
                {
                    sel.Elements.Add(elem);
                }
            }
        }
        trans.Commit();
        
return Result.Succeeded;
    }
}
url:

转载于:https://www.cnblogs.com/greatverve/p/FindReferencesWithContextByDirection.html

你可能感兴趣的文章
Exchanger 应用
查看>>
Chosen:Select 选择框的华丽变身 -- 值的读取和初始化
查看>>
Linux Shell 编程系列
查看>>
抖音API分析
查看>>
Activity之间通过Intent传递复杂Customer Object的两种方式
查看>>
每天一个linux命令(34):ifconfig命令
查看>>
20150914咱实验室迎新会
查看>>
HtmlParser爬取网页数据
查看>>
label设置列间距和首行缩进
查看>>
钓鱼游戏源码分享
查看>>
RandomAccessFile、FileInput和OutputStream的区别
查看>>
Docker实践
查看>>
Spring Integration
查看>>
jdbc,hibernate,mybatis调用存储过程
查看>>
PHP mysql_fetch_row() 函数
查看>>
Shell脚本编写教程
查看>>
【00】why集搜客网络爬虫?
查看>>
css鼠标样式-手型
查看>>
python小程序之文件整理
查看>>
git 放弃本地修改 强制更新
查看>>