【问题标题】:How to get extents in a drafting view in Revit如何在 Revit 中的绘图视图中获取范围
【发布时间】:2011-11-14 05:20:04
【问题描述】:

我希望能够根据绘图的 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);

【问题讨论】:

    标签: c# revit revit-api


    【解决方案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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 2014-09-18
      • 1970-01-01
      相关资源
      最近更新 更多