Revit二次开发---隐藏遮挡元素

背景:冲突检测完成后需要显示相互碰撞的元素并截图,因为会有房子、地面等等大的模型,所以经常会遇到元素被遮挡。

解决思路:

1、将项目的“视觉样式”改为“隐藏线”模式(选中截图时更清晰的显示)、设置视图方向为俯视(从上往下看)。

2、创建一条模型线用于检测都有哪些遮挡元素,并将元素隐藏。

3、截图后再把隐藏的元素显示出来。

//设置项目视觉样式
uiDoc.ActiveView.get_Parameter(BuiltInParameter.MODEL_GRAPHICS).Set(2);
//设置视图为俯视
View3D view = uiDoc.ActiveView as View3D;
view.OrientTo(-XYZ.BasisZ);

//根据元素中点创建模型线,过滤出遮挡元素
XYZ ptStart = null;
if(element.Location is LocationPoint)
{
    LocationPoint lp = element.Location as LocationPoint;
    ptStart = lp.Point;
}
else if(element.Location is LocationCurve)
{
    LocationCurve lc = element.Location as LocationCurve;
    ptStart = (lc.Curve.GetEndPoint(0) + lc.Curve.GetEndPoint(1)) / 2;
}
else
{
    BoundingBoxXYZ box = element.get_BoundingBox(doc.ActiveView);
    ptStart = (box.Min + box.Max) / 2;
}
XYZ ptEnd = new XYZ(ptStart.X,ptStart.Y,ptStart.Z + 100);
ModelCurve mc = DrawModelCurve(doc,Line.CreateBound(ptStart,ptEnd));
BoundingBoxXYZ mcBox = mc.get_BoundingBoxXYZ(doc.ActiveView);
Outline ol = new Outline(mcBox.Min,mcBox.Max);
BoundingBoxIntersectsFilter boxFilter = new BoundingBoxIntersectsFilter(ol);
FilteredElementCollector fec = new FilteredElementCollector(doc);
List<ElementId> ids = fec.WherePasses(boxFilter).ToElementIds().ToList();

//设置遮挡元素隐藏
uiDoc.ActiveView.HideElements(ids);

//截图
ImageExportOptions ieo = new ImageExportOptions();
ieo.ZoomType = ZoomType.FitToPage;
iep.ExportRange = ExportRange.VisibleRegionOfCurrentView;
ieo.FilePath = @"d:\";
ieo.GLRandWFViewsFileType = ImageFileType.JPEGMedium;
ieo.ShadowViewsFileType =  ImageFileType.JPEGMedium;
doc.ExportImage(ieo);
//显示遮挡元素
uiDoc.ActiveView.UnhideElements(ids);

DrawModelCurve

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嘿呦嘿呦嘿呦嘿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值