2017-02-27 78 views
0

我在截面視圖內部有一些細節線,我想通過該部分的CropBox的中點進行鏡像。我正在使用ElementTransformUtils.MirrorElements嘗試完成此操作。但是,我還沒有找到正確的平面來反映細節線。我試過Plane.CreateByNormalAndOrigin(section.ViewDirection, section.Origin)detailLine.SketchPlane.GetPlane(),但沒有一個鏡像的細節線。使用Revit API在剖面視圖中對鏡頭細節進行鏡像

Mirroring Detail Lines

什麼是實現這一目標的正確方法是什麼?

回答

0

我能得到我的細節跨越的中點鏡像ViewSection.CropBox但它相當複雜。我發現ViewSection.Origin是項目座標系統中的一個點。另一方面,ViewSection.CropBox不會在項目座標系中給出它的最小值和最大值,而是會給出CropBox相對於ViewSection.Origin的位置。使用ViewSection.OriginViewSection.CropBox,您可以計算項目座標系中ViewSection.CropBox的最小值和最大值。最後,您需要使用最小值和最大值來查找ViewSection.CropBox的中點,然後在該點上進行鏡像。

下面是我使用,使我能找到的最小和最大使用單一功能

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

public enum MinOrMax 
{ 
    Invalid, 
    Min, 
    Max 
} 

這裏的函數查找最小或最大的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我們不使用最小值和最大值之間的中點,而是使用原點。這是因爲我們的細節工作僅存在於2D中,即使我們指定了深度CropBox並且細節工作與ViewSection.Origin的深度相同。

下面是我用得到的中點代碼:

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); 
0

是的,你提到的飛機不會像你期望的那樣反射。

我需要一個垂直於細節線的平面。

這將鏡像水平細節線,例如您從右向左顯示或反之亦然。

您可以確定鏡面從細節線本身正常的,產地:

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

或多或少...