背景:冲突检测完成后需要显示相互碰撞的元素并截图,因为会有房子、地面等等大的模型,所以经常会遇到元素被遮挡。
解决思路:
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);