我希望能够根据绘图的 x 值范围的中点镜像绘图视图中的所有元素。xMidpoint
在下面的示例中是我想要得到的。
我有 Revit 2012 可用。
int xMidpoint;
Plane plane = new Plane(new XYZ(1,0,0), new XYZ(xMidpoint,0,0));
ElementTransformUtils.MirrorElements(document, idsOfElementsToMirror, plane);
在浏览了 Revit API 一段时间后,我想出了下面的代码来查找中点。它使用每个元素的边界范围来查找图形中的最大和最小 x 值。
FilteredElementCollector allElementsInView = new FilteredElementCollector(document, document.ActiveView.Id);
IList elementsInView = (IList)allElementsInView.ToElements();
List<ElementId> idsOfElementsToMirror = new List<ElementId>();
double drawingMaxX = double.MinValue;
double drawingMinX = double.MaxValue;
foreach (Element element in elementsInView)
{
if (element.Category == null)
continue;
if (ElementTransformUtils.CanMirrorElement(document, element.Id) == false)
continue;
BoundingBoxXYZ elementBoundingBox = element.get_BoundingBox(document.ActiveView.Id);
if(elementBoundingBox == null)
continue;
if (elementBoundingBox.Max.X > drawingMaxX)
drawingMaxX = elementBoundingBox.Max.X;
if (elementBoundingBox.Min.X < drawingMinX)
drawingMinX = elementBoundingBox.Min.X;
idsOfElementsToMirror.Add(element.Id);
}
double xMidpoint = ((drawingMaxX - drawingMinX) / 2.0) + drawingMinX;