使用Revit API镜像剖视图中的详细信息

时间:2017-02-27 14:38:23

标签: c# revit-api revit

我在剖面视图中有一些细节线,我希望在该区域的CropBox的中点处镜像。我正在使用ElementTransformUtils.MirrorElements来尝试完成此任务。但是,我还没有找到正确的平面来镜像细节线。我已经尝试了Plane.CreateByNormalAndOrigin(section.ViewDirection, section.Origin)detailLine.SketchPlane.GetPlane(),但没有一个镜像细节线。

Mirroring Detail Lines

完成此任务的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

是的,你提到的飞机不会像你期望的那样镜像。

我需要一个垂直于细节线的平面。

这将反映水平细节线,例如从右到左显示,反之亦然。

您可以从细节线本身确定镜像平面法线和原点:

  XYZ p = detail line start point
  XYZ q = detail line end point
  XYZ normal = q - p
  Plane plane = Plane.CreateByNormalAndOrigin(p, normal)

或多或少......

答案 1 :(得分:0)

我能够将我的细节镜像到ViewSection.CropBox的中点,但它相当复杂。我发现ViewSection.Origin是项目坐标系中的一个点。另一方面,ViewSection.CropBox不会在项目坐标系中为您提供Min和Max,而是为您提供CropBox相对于ViewSection.Origin的位置。使用ViewSection.OriginViewSection.CropBox,您可以计算项目坐标系中ViewSection.CropBox的最小值和最大值。最后,您需要使用这些最小值和最大值来查找ViewSection.CropBox的中点,然后在该点上进行镜像。

以下是我使用的一些辅助类,以便我可以使用单个函数找到Min和Max

public enum PointComponent
{
  Invalid,
  X,
  Y,
  Z
}

public enum MinOrMax
{
  Invalid,
  Min,
  Max
}

这是找到CropBox最小值或最大值的X,Y或Z分量的函数:

private double GetSectionCropBoxOrigin(ViewSection section,
  PointComponent pointComponent, MinOrMax minOrMax)
{
  double cropBoxOrigin;

  double sectionOrigin, viewDirection, upDirection, rightDirection;

  switch (pointComponent)
  {
    case PointComponent.X:
      sectionOrigin = section.Origin.X;
      viewDirection = section.ViewDirection.X;
      upDirection = section.UpDirection.X;
      rightDirection = section.RightDirection.X;
      break;
    case PointComponent.Y:
      sectionOrigin = section.Origin.Y;
      viewDirection = section.ViewDirection.Y;
      upDirection = section.UpDirection.Y;
      rightDirection = section.RightDirection.Y;
      break;
    case PointComponent.Z:
      sectionOrigin = section.Origin.Z;
      viewDirection = section.ViewDirection.Z;
      upDirection = section.UpDirection.Z;
      rightDirection = section.RightDirection.Z;
      break;
    default:
      throw new InvalidOperationException();
  }

  double cropX, cropY;

  switch (minOrMax)
  {
    case MinOrMax.Min:
      cropX = section.CropBox.Min.X;
      cropY = section.CropBox.Min.Y;
      break;
    case MinOrMax.Max:
      cropX = section.CropBox.Max.X;
      cropY = section.CropBox.Max.Y;
      break;
    default:
      throw new InvalidOperationException();
  }

  if (Math.Abs(viewDirection) == 1)
    cropBoxOrigin = sectionOrigin;
  else if (Math.Abs(upDirection) == 1)
    cropBoxOrigin = sectionOrigin + (cropY * upDirection);
  else if (Math.Abs(rightDirection) == 1)
    cropBoxOrigin = sectionOrigin + (cropX * rightDirection);
  else
    throw new InvalidOperationException();

  return cropBoxOrigin;
}

请注意,对于PointComponent.Z,我们不使用最小值和最大值之间的中点,而是使用原点。这是因为即使我们指定CropBox深度并且细节工作与ViewSection.Origin处于同一深度,我们的详细工作也仅存在于2D中。

这是我用来获得中点的代码:

private XYZ Get3dMidpoint(XYZ start, XYZ end)
{
    double x = (start.X + end.X) / 2.0;
    double y = (start.Y + end.Y) / 2.0;
    double z = (start.Z + end.Z) / 2.0;

    return new XYZ(x, y, z);
}

最后,这是将所有内容组合在一起并得到镜像平面的代码:

XYZ cropBoxMinInGlobalCoordinates = new XYZ(
    GetSectionCropBoxOrigin(section, PointComponent.X, MinOrMax.Min),
    GetSectionCropBoxOrigin(section, PointComponent.Y, MinOrMax.Min),
    GetSectionCropBoxOrigin(section, PointComponent.Z, MinOrMax.Min)
);
XYZ cropBoxMaxInGlobalCoordinates = new XYZ(
    GetSectionCropBoxOrigin(section, PointComponent.X, MinOrMax.Max),
    GetSectionCropBoxOrigin(section, PointComponent.Y, MinOrMax.Max),
    GetSectionCropBoxOrigin(section, PointComponent.Z, MinOrMax.Max)
);
XYZ cropBoxOriginInGlobalCoordinates = 
  Get3dMidpoint(cropBoxMinInGlobalCoordinates, cropBoxMaxInGlobalCoordinates);

Plane mirrorPlane = 
  Plane.CreateByNormalAndOrigin(section.RightDirection, cropBoxOriginInGlobalCoordinates);