2011-09-08 63 views
1

我希望能夠根據繪圖的x值範圍的中點來映射繪圖視圖中的所有元素。下面的例子中的xMidpoint就是我想要得到的。如何在Revit的繪圖視圖中獲取範圍

我有Revit 2012可用。

int xMidpoint; 
Plane plane = new Plane(new XYZ(1,0,0), new XYZ(xMidpoint,0,0)); 
ElementTransformUtils.MirrorElements(document, idsOfElementsToMirror, plane); 

回答

1

在瀏覽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; 
相關問題