How to get extents in a drafting view in Revit
I want to 开发者_JS百科be able to mirror all of the elements in a drafting view according to the midpoint of the x value extents of the drawing. xMidpoint
in the example below is what I'm trying to get.
I have Revit 2012 available.
int xMidpoint;
Plane plane = new Plane(new XYZ(1,0,0), new XYZ(xMidpoint,0,0));
ElementTransformUtils.MirrorElements(document, idsOfElementsToMirror, plane);
After browsing the Revit API for a while I came up with the code below for finding the midpoint. It uses the bounding extents of each element to find the maximum and minimum x values in the drawing.
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;
精彩评论