Revit二次開發——矩形樓板開洞

以管道爲例,
1.取得Curve

LocationCurve locationCurve = elemPick.Location as LocationCurve;
                if (locationCurve != null)
                    curve = locationCurve.Curve;

2.取得樓板的面

public Face GetFloorFace(Floor floor)
    {
        Face normalFace = null;
        Options opt = new Options();
        opt.ComputeReferences = true;
        opt.DetailLevel = ViewDetailLevel.Medium;//視圖的詳細程度
        GeometryElement ge = floor.get_Geometry(opt);

        foreach (var geobject in ge)
        {
            Solid solid = geobject as Solid;
            if (solid != null && solid.Faces.Size > 0)
            {
                //   MessageBox.Show(solid.Faces.Size.ToString());
                //int count = 0;
                foreach (Face face in solid.Faces)
                {
                    PlanarFace planarFace = face as PlanarFace;
                    if (planarFace != null)
                    {
                        if (planarFace.FaceNormal.AngleTo(new XYZ(0, 0, 1)) < 0.01 || (planarFace.FaceNormal.AngleTo(new XYZ(0, 0, -1)) < 0.01))
                        {
                            //MessageBox.Show(planarFace.FaceNormal.X + "\n" + planarFace.FaceNormal.Y + "\n" + planarFace.FaceNormal.Z);
                            normalFace = face;
                        }
                    }
                }
            }
        }
        return normalFace;
    }

3.取得管道和樓板的交點
參照代碼:

public XYZ GetIntersection(Face face, Curve curve)
    {
        XYZ intersection = null;
        IntersectionResultArray resultArray = new IntersectionResultArray();
        SetComparisonResult setComparisionRes = face.Intersect(curve, out resultArray);
        if (SetComparisonResult.Disjoint != setComparisionRes)
        {
            if (!resultArray.IsEmpty)
            {
                intersection = resultArray.get_Item(0).XYZPoint;
            }
        }
        return intersection;
    }

4.取得洞口的模型線

public CurveArray GetCurveArrayRec(XYZ intersection, double width, double height)
    {
        CurveArray curveArray = new CurveArray();

        XYZ xyz1 = intersection + new XYZ(width / 304.8 / 2, height / 304.8 / 2, 0);
        XYZ xyz2 = intersection + new XYZ(width / 304.8 / 2, -height / 304.8 / 2, 0);
        XYZ xyz3 = intersection + new XYZ(-width / 304.8 / 2, -height / 304.8 / 2, 0);
        XYZ xyz4 = intersection + new XYZ(-width / 304.8 / 2, height / 304.8 / 2, 0);

        curveArray.Append(Line.CreateBound(xyz1, xyz2) as Curve);
        curveArray.Append(Line.CreateBound(xyz1, xyz4) as Curve);
        curveArray.Append(Line.CreateBound(xyz2, xyz3) as Curve);
        curveArray.Append(Line.CreateBound(xyz3, xyz4) as Curve);

        return curveArray;
    }

5.創建洞口:

doc.Create.NewOpening(floor, curveArray, true);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章