Esempio n. 1
0
        public static XYZ CheckComputeNormal(this PlanarFace planarFace, Transform transform)
        {
            XYZ p1        = planarFace.ComputeNormal(UV.Zero);
            XYZ p1project = transform.OfVector(p1).Normalize();

            return(p1project);
        }
Esempio n. 2
0
        /// <summary>
        /// Return the XY vertices of the bottom horizontal
        /// face of the given element, scaled to millimetres,
        /// in a string of space-separated integer values.
        /// Prepend the face's area in square meters and its
        /// Z elevation coordinate, comma-separated.
        /// </summary>
        public static string GetBottomFaceBoundaryStringZArea(
            Element e,
            out double z,
            out double area)
        {
            GeometryElement geo = e.get_Geometry(_geo_opt);

            PlanarFace bottom_face = GetBottomHorizontalFace(geo);

            string s = null;

            z = area = -Double.MaxValue;

            if (null != bottom_face)
            {
                z    = bottom_face.Origin.Z;
                area = bottom_face.Area;

                //Z = Util.FootToMmInt( bottom_face.Origin.Z )
                //  .ToString();

                //Area = Util.RealString(
                //  Util.SquareFootToSquareMeter(
                //    bottom_face.Area ) );

                List <XYZ> vertices = GetFirstEdgeLoopVertices(
                    bottom_face);

                s = XyzListTo2dPointString(vertices);
            }
            return(s);
        }
        private static Face GetCloseFace(Element e,
                                         XYZ p,
                                         XYZ normal,
                                         Options opt)
        {
            Face            face         = null;
            double          min_distance = double.MaxValue;
            GeometryElement geo          = e.get_Geometry(opt);

            foreach (GeometryObject obj in geo)
            {
                Solid solid = obj as Solid;
                if (solid != null)
                {
                    FaceArray fa = solid.Faces;
                    foreach (Face f in fa)
                    {
                        PlanarFace pf = f as PlanarFace;
                        if (null != pf && Util.IsParallel(normal, pf.FaceNormal))
                        {
                            XYZ    v = p - pf.Origin;
                            double d = v.DotProduct(-pf.FaceNormal);
                            if (d < min_distance)
                            {
                                face         = f;
                                min_distance = d;
                            }
                        }
                    }
                }
            }

            return(face);
        }
Esempio n. 4
0
        public PlanarFace GetFace(Element element)
        {
            Options opt = new Options();
            // Get geometry element of the selected element
            GeometryElement geoElement = element.get_Geometry(opt);

            PlanarFace pf = null;

            // Get geometry object
            foreach (GeometryObject geoObject in geoElement)
            {
                // Get the geometry instance which contains the geometry information
                Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;
                if (null != instance)
                {
                    GeometryElement instanceGeometryElement = instance.GetInstanceGeometry();
                    foreach (GeometryObject instObj in instanceGeometryElement)
                    {
                        Solid solid = instObj as Solid;
                        if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }
                        // Get the faces and edges from solid, and transform the formed points
                        foreach (Face face in solid.Faces)
                        {
                            //face.ComputeNormal(new UV(0.5, 0.5));
                            pf = face as PlanarFace;
                        }
                    }
                }
            }

            return(pf);
        }
Esempio n. 5
0
        /// <summary>
        /// Return the bottom horizontal face, if found, or null
        /// </summary>
        static PlanarFace GetBottomHorizontalFace(
            GeometryElement geo)
        {
            PlanarFace bottom_face = null;

            foreach (GeometryObject obj in geo)
            {
                Solid solid = obj as Solid;

                if (null != solid)
                {
                    foreach (Face f in solid.Faces)
                    {
                        PlanarFace pf = f as PlanarFace;

                        if (null != pf &&
                            IsHorizontal(pf) &&
                            (null == bottom_face ||
                             bottom_face.Origin.Z > pf.Origin.Z))
                        {
                            bottom_face = pf;
                        }
                    }
                }
            }
            return(bottom_face);
        }
Esempio n. 6
0
        public Result Execute(ExternalCommandData commandData,
                              ref string messege,
                              ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document      doc   = uiApp.ActiveUIDocument.Document;

            try
            {
                Reference faceRef = uiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Face
                                                                                , new PlanarFacePickFilter(doc), "Please pick a planar face to set the work plane. ESC for cancel");
                GeometryObject geomObject = doc.GetElement(faceRef).GetGeometryObjectFromReference(faceRef);
                PlanarFace     pf         = geomObject as PlanarFace;

                using (Transaction t = new Transaction(doc, "SetWorkPlane"))
                {
                    t.Start("SetWorkPlane");
                    doc.ActiveView.SketchPlane = SketchPlane.Create(doc, pf.GetSurface() as Plane);
                    t.Commit();
                }
                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                messege = ex.Message;
                return(Result.Failed);
            }
        }
Esempio n. 7
0
        Stream(ArrayList data, PlanarFace face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PlanarFace)));

            data.Add(new Snoop.Data.Xyz("Origin", face.Origin));
            data.Add(new Snoop.Data.Xyz("Normal", face.ComputeNormal(UV.Zero)));
        }
Esempio n. 8
0
        /// <summary>
        /// The method is used to create dimension between two faces
        /// </summary>
        /// <param name="view">the view</param>
        /// <param name="face1">the first face</param>
        /// <param name="face2">the second face</param>
        /// <returns>the new dimension</returns>
        public Dimension AddDimension(View view, Face face1, Face face2)
        {
            Dimension dim;

            Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ();
            Autodesk.Revit.DB.XYZ endPoint   = new Autodesk.Revit.DB.XYZ();
            Line           line;
            Reference      ref1;
            Reference      ref2;
            ReferenceArray refArray = new ReferenceArray();
            PlanarFace     pFace1   = face1 as PlanarFace;

            ref1 = pFace1.Reference;
            PlanarFace pFace2 = face2 as PlanarFace;

            ref2 = pFace2.Reference;
            if (null != ref1 && null != ref2)
            {
                refArray.Append(ref1);
                refArray.Append(ref2);
            }
            startPoint = pFace1.Origin;
            endPoint   = new Autodesk.Revit.DB.XYZ(startPoint.X, pFace2.Origin.Y, startPoint.Z);
            SubTransaction subTransaction = new SubTransaction(m_document);

            subTransaction.Start();
            line = Line.CreateBound(startPoint, endPoint);
            dim  = m_document.FamilyCreate.NewDimension(view, line, refArray);
            subTransaction.Commit();
            return(dim);
        }
        IList <CurveLoop> GetCurveLoops(Document doc, Reference rf)
        {
            IList <CurveLoop> curveloop      = new List <CurveLoop>();
            GeometryObject    geometryObject = doc.GetElement(rf).GetGeometryObjectFromReference(rf);

            try
            {
                PlanarFace planarFace = geometryObject as PlanarFace;
                curveloop = planarFace.GetEdgesAsCurveLoops();
            }
            catch
            {
                HermiteFace hermiteFace = geometryObject as HermiteFace;
                if (hermiteFace == null)
                {
                    RuledFace ruledFace = geometryObject as RuledFace;
                    curveloop = ruledFace.GetEdgesAsCurveLoops();
                }
                else
                {
                    curveloop = hermiteFace.GetEdgesAsCurveLoops();
                }
            }
            return(curveloop);
        }
Esempio n. 10
0
        public static Plane ToPlane(this PlanarFace planarFace)
        {
            XYZ origon    = planarFace.Origin;
            XYZ normalXyz = planarFace.FaceNormal;

            return(Plane.CreateByNormalAndOrigin(normalXyz, origon));
        }
Esempio n. 11
0
        /// <summary>
        /// 拿到一条线到一个楼板上的投影,此处针对的是某一个楼板
        /// </summary>
        /// <param name="line"></param>
        /// <param name="floor"></param>
        /// <returns></returns>
        public Curve FindFloorcurve(Curve line, Floor floor)
        {
            var    floorgeom = floor.get_Geometry(GetgeometryOptions());
            var    geomobj   = floorgeom.First <GeometryObject>();
            Solid  floorobj  = geomobj as Solid;
            double facearea  = 0;

            PlanarFace pf        = null;
            PlanarFace pf_target = null;

            foreach (Face face in floorobj.Faces)
            {
                pf = face as PlanarFace;
                if (pf.Area > facearea && pf.FaceNormal.Z >= 0)
                {
                    //拿到楼板上面的一个面
                    facearea  = pf.Area;
                    pf_target = pf;
                }
            }

            TaskDialog.Show("ss", pf_target.Area.ToString());
            XYZ   point_start = pf_target.Project(line.GetEndPoint(0)).XYZPoint;
            XYZ   point_end   = pf_target.Project(line.GetEndPoint(1)).XYZPoint;
            Curve curve       = Line.CreateBound(point_start, point_end);

            return(curve);
        }
        public PlanarFace Facexanhat(XYZ point, XYZ direction, IList <PlanarFace> listFaces, Transform transform)
        {
            PlanarFace planarFace = null;
            double     num        = double.MinValue;
            PLane3D    plane3D    = new PLane3D(point, direction);

            foreach (PlanarFace i in listFaces)
            {
                XYZ  xyz   = transform.OfVector(i.FaceNormal);
                XYZ  xyz2  = direction.CrossProduct(xyz);
                bool check = xyz2.GetLength() > 0.001 || xyz.DotProduct(direction) < 0.0;
                if (!check)
                {
                    double num2  = plane3D.DistancepointtoPlane(transform.OfPoint(i.Origin));
                    bool   flag2 = num2 < 0.001;
                    if (!flag2)
                    {
                        bool flag3 = num2 > num;
                        if (flag3)
                        {
                            planarFace = i;
                            num        = num2;
                        }
                    }
                }
            }
            return(planarFace);
        }
Esempio n. 13
0
        /// <summary>
        /// 根据指定的平面与变换关系拉伸出一个实体
        /// </summary>
        /// <param name="face"> </param>
        /// <param name="transform"> 将 face 对象 转换到模型空间中所需要进行的变换</param>
        /// <param name="thickNess"> 面层的厚度,单位为米 </param>
        /// <returns></returns>
        private Solid ExtrudeSolid(PlanarFace face, Transform transform, double thickNess)
        {
            Solid solid = null;

            IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();

            //drawCurve(curveLoops);

            // 要在实体还未创建之前就定位好其在模型空间中的位置,因为后面要依据此位置来进行相交判断。
            foreach (CurveLoop curveLoop in curveLoops)
            {
                curveLoop.Transform(transform);
            }

            //IList<CurveLoop> curveLoops;
            //CurvesFormator.GetContiguousCurvesFromEdgeArrArray(face.EdgeLoops, out curveLoops);

            XYZ extrusionDir = transform.OfVector(face.FaceNormal);

            solid = GeometryCreationUtilities.CreateExtrusionGeometry(
                profileLoops: curveLoops,
                extrusionDir: extrusionDir,
                extrusionDist: UnitUtils.ConvertToInternalUnits(thickNess, DisplayUnitType.DUT_METERS));
            return(solid);
        }
Esempio n. 14
0
        /// <summary>
        /// 将楼梯中所有与选择的表面相同方向的面上都生成面层
        /// </summary>
        /// <param name="docTran">  </param>
        /// <param name="elem"> 用来生成面层的单元。此函数会搜索此单元中所有与 baseFace 同法向的面,并进行面层的绘制 </param>
        /// <param name="pickedFace"> 楼梯中用来生成面层的那个面</param>
        /// <param name="faceOp"> 生成面层的选项</param>
        /// <param name="transf"> </param>
        /// <returns></returns>
        private IList <DirectShape> ExtendToFacesWithSameNormal(Transaction docTran, Element elem, PlanarFace pickedFace, FaceOptions faceOp, Transform transf)
        {
            IList <DirectShape> directShapes = new List <DirectShape>();

            // 值中的false 表示solid 是 Family中的solid,后期还要再进行一次transform才能变换 Familyinstance 所对应的位置
            Dictionary <Solid, bool> solids = GeoHelper.GetSolidsInModel(elem, GeoHelper.SolidVolumnConstraint.Positive);

            foreach (Solid solid in solids.Keys)
            {
                foreach (Face face in solid.Faces)
                {
                    if ((face is PlanarFace))
                    {
                        PlanarFace planarFace = (PlanarFace)face;

                        if (GeoHelper.IsSameDirection(planarFace.FaceNormal, transf.OfVector(pickedFace.FaceNormal)))
                        {
                            DirectShape ds = ConstructSurfaceFromPlanarFace(docTran, planarFace, faceOp, Transform.Identity);

                            if (ds != null)
                            {
                                directShapes.Add(ds);
                            }
                        }
                    }
                }
            }

            return(directShapes);
        }
Esempio n. 15
0
        public PlanarFace PlanarFaceDistanceToMin(List <PlanarFace> listPlanarFaces, XYZ point)
        {
            PlanarFace face = null;
            double     min  = 100;

            foreach (PlanarFace planar in listPlanarFaces)
            {
                var fg = planar.Project(point);
                if (fg == null)
                {
                    continue;
                }
                else
                {
                    XYZ Tert = fg.XYZPoint;
                    if (Tert != null)
                    {
                        double spa = point.DistanceTo(planar.Project(point).XYZPoint);
                        if (spa < min)
                        {
                            min  = spa;
                            face = planar;
                        }
                    }
                }
            }
            return(face);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;

            uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;

            doc = uidoc.Document;
            sel = uidoc.Selection;
            Reference      rf        = sel.PickObject(ObjectType.Face, "Select Face");
            Element        ele       = doc.GetElement(rf);
            GeometryObject geoobject = ele.GetGeometryObjectFromReference(rf);
            PlanarFace     face      = geoobject as PlanarFace;
            Plane          plane     = face.Faceby3pointPlane();
            XYZ            direction = face.ComputeNormal(UV.Zero);

            using (Transaction tran = new Transaction(doc, "Set view by face"))
            {
                tran.Start();
                SketchPlane skt    = SketchPlane.Create(doc, plane);
                View3D      view3d = doc.ActiveView as View3D;
                view3d.OrientTo(plane.Normal);
                doc.ActiveView.SketchPlane = skt;
                uidoc.RefreshActiveView();
                uidoc.ShowElements(ele.Id);
                tran.Commit();
            }
            return(Result.Succeeded);
        }
Esempio n. 17
0
        public static void FindFloorslope(Floor floor, out double degree, out double thousand)
        {
            var    floorgeom = floor.get_Geometry(FloorTools.GetgeometryOptions());
            var    geomobj   = floorgeom.First <GeometryObject>();
            Solid  floorobj  = geomobj as Solid;
            double facearea  = 0;
            double cos_angle = 0;

            PlanarFace pf = null;

            foreach (Face face in floorobj.Faces)
            {
                pf = face as PlanarFace;
                if (pf.Area > facearea && pf.FaceNormal.Z >= 0)
                {
                    facearea  = pf.Area;
                    cos_angle = pf.FaceNormal.Z / Math.Sqrt(Math.Pow(pf.FaceNormal.X, 2) + Math.Pow(pf.FaceNormal.Y, 2) + Math.Pow(pf.FaceNormal.Z, 2));
                }
            }
            double angle_degree   = Math.Round(Math.Acos(cos_angle) / Math.PI * 180, 3);
            double angle_thousand = Math.Tan(Math.Acos(cos_angle)) * 1000;

            degree   = Math.Round(angle_degree, 4);
            thousand = Math.Round(angle_thousand, 3);
        }
        //methdo to get the bottom face of element passed to it
        public static PlanarFace GetBottomFace(Element ele)
        {
            try
            {
                Options         opt    = new Options();
                GeometryElement geoEle = ele.get_Geometry(opt);
                IEnumerator     enu    = geoEle.GetEnumerator();
                enu.Reset();

                while (enu.MoveNext())
                {
                    Solid solid = enu.Current as Solid;
                    if (null != solid)
                    {
                        foreach (Face face in solid.Faces)
                        {
                            PlanarFace pf = face as PlanarFace;
                            if (null != pf)
                            {
                                if (pf.Normal.Z < 0)
                                {
                                    return(pf);
                                }
                            }
                        }
                    }
                }

                return(null);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 19
0
        Stream(ArrayList data, Face face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Face)));

            data.Add(new Snoop.Data.Double("Area", face.Area));
            ///TODO: Restore: data.Add(new Snoop.Data.Object("Material element", face.MaterialElement));
            data.Add(new Snoop.Data.Bool("Is two-sided", face.IsTwoSided));
            data.Add(new Snoop.Data.Enumerable("Edge loops", face.EdgeLoops));
            data.Add(new Snoop.Data.Object("Triangulate", face.Triangulate()));
            data.Add(new Snoop.Data.Object("Reference", face.Reference));

            ConicalFace conicalFace = face as ConicalFace;

            if (conicalFace != null)
            {
                Stream(data, conicalFace);
                return;
            }

            CylindricalFace cylFace = face as CylindricalFace;

            if (cylFace != null)
            {
                Stream(data, cylFace);
                return;
            }

            HermiteFace hermiteFace = face as HermiteFace;

            if (hermiteFace != null)
            {
                Stream(data, hermiteFace);
                return;
            }

            PlanarFace planarFace = face as PlanarFace;

            if (planarFace != null)
            {
                Stream(data, planarFace);
                return;
            }

            RevolvedFace revlFace = face as RevolvedFace;

            if (revlFace != null)
            {
                Stream(data, revlFace);
                return;
            }

            RuledFace ruledFace = face as RuledFace;

            if (ruledFace != null)
            {
                Stream(data, ruledFace);
                return;
            }
        }
Esempio n. 20
0
 public static Plane GetPlaneWithBasisY(PlanarFace f, XYZ vecY)
 {
     if (!GeomUtil.IsEqual(GeomUtil.DotMatrix(vecY, f.FaceNormal), 0))
     {
         throw new Exception("VecY is not perpendicular with Normal!");
     }
     return(Plane.CreateByOriginAndBasis(f.Origin, GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecY, f.FaceNormal)), vecY));
 }
Esempio n. 21
0
        /// <summary>
        /// Return an arbitrary point on a planar face,
        /// namely the midpoint of the first mesh triangle.
        /// </summary>
        XYZ PointOnFace(PlanarFace face)
        {
            Mesh mesh = face.Triangulate();

            return(0 < mesh.NumTriangles
        ? MedianPoint(mesh.get_Triangle(0))
        : XYZ.Zero);
        }
        private DirectionInfo GetWallNormalInfo()
        {
            PlanarFace wallSideFace  = Wall.Document.GetElement(WallSideFaceRef).GetGeometryObjectFromReference(WallSideFaceRef) as PlanarFace;
            XYZ        wallNormalDir = _transform.OfPoint(wallSideFace?.FaceNormal);
            var        l             = Line.CreateBound(MidPoint, wallNormalDir);

            return(new DirectionInfo(l, Util.GetVector(l)));
        }
Esempio n. 23
0
        private static bool parallel(PlanarFace pf, XYZ hand, XYZ facing)
        {
            var handDot   = pf.FaceNormal.DotProduct(hand);
            var facingDot = pf.FaceNormal.DotProduct(facing);

            return(handDot.IsAlmostEqualByDifference(0) &&
                   facingDot.IsAlmostEqualByDifference(0));
        }
Esempio n. 24
0
        /// <summary>
        /// 拿到一条线投影到一个面上面
        /// </summary>
        /// <param name="line"></param>
        /// <param name="face_refer"></param>
        /// <returns></returns>
        public Curve FindFacecurve(Curve line, PlanarFace face)
        {
            XYZ   point_start = face.Project(line.GetEndPoint(0)).XYZPoint;
            XYZ   point_end   = face.Project(line.GetEndPoint(1)).XYZPoint;
            Curve curve       = Line.CreateBound(point_start, point_end);

            return(curve);
        }
Esempio n. 25
0
        public static double PointToFace(XYZ point, PlanarFace face, Transform transform)
        {
            XYZ     normal     = transform.OfVector(face.FaceNormal);
            XYZ     origin     = transform.OfPoint(face.Origin);
            PLane3D plane3DLib = new PLane3D(origin, normal);

            return(plane3DLib.DistanceFromPointToPlane(point));
        }
Esempio n. 26
0
 /// <summary>
 /// Creates a selection filter that will let only PlanarFace-References pass
 /// </summary>
 /// <param name="doc"></param>
 /// <returns></returns>
 public static IReferenceSelectionFilter GetPlanarFaceFilter(Document doc)
 {
     return(GetReferenceFilter((reference, xyz) => {
         Element element = doc.GetElement(reference);
         PlanarFace planarFace = element.GetGeometryObjectFromReference(reference) as PlanarFace;
         return planarFace != null;
     }));
 }
Esempio n. 27
0
        /// <summary>
        /// Compute the distance between two planar faces.
        /// </summary>
        /// <param name="face1">Face 1</param>
        /// <param name="face2">Face 2</param>
        /// <returns>Distance of the two planar faces</returns>
        private static double GetDistance(PlanarFace face1, PlanarFace face2)
        {
            BoundingBoxUV      boxUV    = face2.GetBoundingBox();
            UV                 center   = (boxUV.Max + boxUV.Min) * 0.5;
            XYZ                centerPt = face2.Evaluate(center);
            IntersectionResult result   = face1.Project(centerPt);

            return(face1.Project(centerPt).Distance);
        }
Esempio n. 28
0
        /// <summary>
        /// Check if the given bottom edge was shared by a trapezoid face with left edge vertical.
        /// </summary>
        /// <param name="hostNormal">Corbel Host face Normal</param>
        /// <param name="corbelBottomFace">Bottom Face of Corbel</param>
        /// <param name="bottomEdge">Given bottom edge to test</param>
        /// <param name="trapezoidFace">Output the trapezoid Face</param>
        /// <param name="topEdge">Output trapezoid top edge</param>
        /// <param name="leftEdge">Output trapezoid left edge</param>
        /// <param name="rightEdge">Output trapezoid right edge</param>
        /// <returns>True if there is a trapezoid face share the given bottom edge, otherwise false.</returns>
        private static bool IsTrapezoid(
            XYZ hostNormal, PlanarFace corbelBottomFace, Edge bottomEdge,
            out PlanarFace trapezoidFace, out Edge topEdge,
            out Edge leftEdge, out Edge rightEdge)
        {
            PlanarFace face1 = bottomEdge.get_Face(0) as PlanarFace;
            PlanarFace face2 = bottomEdge.get_Face(1) as PlanarFace;

            trapezoidFace = face1 == corbelBottomFace ? face2 : face1;

            EdgeArray trapezoidFaceEdges = trapezoidFace.EdgeLoops.get_Item(0);
            XYZ       bottomEdgeDir      = (bottomEdge.Evaluate(1.0) - bottomEdge.Evaluate(0.0)).Normalize();
            int       bottomEdgeIndex    = -1;

            topEdge = null;
            for (int i = 0; i < trapezoidFaceEdges.Size; i++)
            {
                Edge edge    = trapezoidFaceEdges.get_Item(i);
                XYZ  edgeDir = (edge.Evaluate(1.0) - edge.Evaluate(0.0)).Normalize();
                if (edgeDir.IsAlmostEqualTo(bottomEdgeDir) ||
                    edgeDir.IsAlmostEqualTo(-bottomEdgeDir))
                {
                    if (edge.Evaluate(0.0).IsAlmostEqualTo(bottomEdge.Evaluate(0.0)))
                    {
                        bottomEdge      = edge;
                        bottomEdgeIndex = i;
                    }
                    else
                    {
                        topEdge = edge;
                    }
                }
            }

            leftEdge  = trapezoidFaceEdges.get_Item((trapezoidFaceEdges.Size + bottomEdgeIndex - 1) % trapezoidFaceEdges.Size);
            rightEdge = trapezoidFaceEdges.get_Item((bottomEdgeIndex + 1) % trapezoidFaceEdges.Size);

            XYZ  leftEdgeDir        = (leftEdge.Evaluate(1.0) - leftEdge.Evaluate(0.0)).Normalize();
            bool isLeftEdgeVertical = false;

            if (leftEdgeDir.IsAlmostEqualTo(hostNormal) ||
                leftEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                isLeftEdgeVertical = true;
            }

            XYZ  rightEdgeDir        = (rightEdge.Evaluate(1.0) - rightEdge.Evaluate(0.0)).Normalize();
            bool rightEdgeIsVertical = false;

            if (rightEdgeDir.IsAlmostEqualTo(hostNormal) ||
                rightEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                rightEdgeIsVertical = true;
            }

            return(isLeftEdgeVertical && !rightEdgeIsVertical);
        }
Esempio n. 29
0
        public List <SpotDimension> CreatSpotDimensionOnFloorInLink(List <ElementId> floorids, View activeview, Document doc, RevitLinkInstance rli, ref string report)
        {
            List <SpotDimension> sds = new List <SpotDimension>();
            var a      = rli.GetTotalTransform();
            int errnum = 0;

            foreach (ElementId id in floorids)
            {
                Floor floor = rli.GetLinkDocument().GetElement(id) as Floor;

                Options option = new Options();
                option.ComputeReferences = true;
                option.View = activeview;
                option.IncludeNonVisibleObjects = false;
                GeometryElement geometry = floor.get_Geometry(option);
                if (geometry == null)
                {
                    continue;
                }
                foreach (GeometryObject geomobj in geometry)
                {
                    Solid gemosolid = geomobj as Solid;
                    if (gemosolid != null)
                    {
                        XYZ center = rli.GetTotalTransform().OfPoint(gemosolid.ComputeCentroid());
                        foreach (Face geomface in gemosolid.Faces)
                        {
                            PlanarFace plane = geomface as PlanarFace;
                            if (plane != null)
                            {
                                if (plane.FaceNormal.X == 0 && plane.FaceNormal.Y == 0 && plane.FaceNormal.Z == 1)
                                {
                                    //get reference for creation
                                    Reference refe = geomface.Reference.CreateLinkReference(rli);
                                    //get points for creation
                                    XYZ origin = center;
                                    XYZ bend   = origin.Add(new XYZ(0, 1, 0));
                                    XYZ end    = origin.Add(new XYZ(1, 1, 0));
                                    XYZ refpt  = origin;
                                    try
                                    {
                                        SpotDimension sd = doc.Create.NewSpotElevation(activeview, refe, origin, bend, end, refpt, false);
                                        sds.Add(sd);
                                    }
                                    catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
                                    {
                                        errnum++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            report += "\n" + "在" + rli.Name + "有" + errnum.ToString() + "个楼板没有生成高程点.";
            return(sds);
        }
Esempio n. 30
0
        /// <summary>
        /// Determine the boundary polygons of the lowest
        /// horizontal planar face of the given solid.
        /// </summary>
        /// <param name="polygons">Return polygonal boundary
        /// loops of lowest horizontal face, i.e. profile of
        /// circumference and holes</param>
        /// <param name="solid">Input solid</param>
        /// <returns>False if no horizontal planar face was
        /// found, else true</returns>
        static bool GetBoundary(
            List <List <XYZ> > polygons,
            Solid solid)
        {
            PlanarFace lowest = null;
            FaceArray  faces  = solid.Faces;

            foreach (Face f in faces)
            {
                PlanarFace pf = f as PlanarFace;
                if (null != pf && Util.IsHorizontal(pf))
                {
                    if ((null == lowest) ||
                        (pf.Origin.Z < lowest.Origin.Z))
                    {
                        lowest = pf;
                    }
                }
            }
            if (null != lowest)
            {
                XYZ            p, q = XYZ.Zero;
                bool           first;
                int            i, n;
                EdgeArrayArray loops = lowest.EdgeLoops;
                foreach (EdgeArray loop in loops)
                {
                    List <XYZ> vertices = new List <XYZ>();
                    first = true;
                    foreach (Edge e in loop)
                    {
                        IList <XYZ> points = e.Tessellate();
                        p = points[0];
                        if (!first)
                        {
                            Debug.Assert(p.IsAlmostEqualTo(q),
                                         "expected subsequent start point"
                                         + " to equal previous end point");
                        }
                        n = points.Count;
                        q = points[n - 1];
                        for (i = 0; i < n - 1; ++i)
                        {
                            XYZ v = points[i];
                            v -= _offset * XYZ.BasisZ;
                            vertices.Add(v);
                        }
                    }
                    q -= _offset * XYZ.BasisZ;
                    Debug.Assert(q.IsAlmostEqualTo(vertices[0]),
                                 "expected last end point to equal"
                                 + " first start point");
                    polygons.Add(vertices);
                }
            }
            return(null != lowest);
        }
Esempio n. 31
0
 Stream(PlanarFace face)
 {
     StreamFaceGeoometry(face);
 }
Esempio n. 32
0
        private void Stream(ArrayList data, PlanarFace face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PlanarFace)));

            data.Add(new Snoop.Data.Xyz("Origin", face.Origin));
            data.Add(new Snoop.Data.Xyz("Normal", face.ComputeNormal(UV.Zero)));
        }
        /// <summary>

        /// <summary>
        /// Determines if the Normal of the PlanarFace is flipped.
        /// </summary>
        /// <param name="planarFace">The planar face.</param>
        /// <returns>True if the normal is flipped.</returns>
        public static bool IsPlanarFaceNormalFlipped(PlanarFace planarFace)
        {
            XYZ planarFaceNormal = planarFace.Normal;
            XYZ faceNormal = planarFace.ComputeNormal(new UV(0, 0));
            return MathUtil.VectorsAreParallel2(planarFaceNormal, faceNormal) == -1;
        }
Esempio n. 34
0
        /// <summary>
        /// Check if the given bottom edge was shared by a trapezoid face with left edge vertical.
        /// </summary>
        /// <param name="hostNormal">Corbel Host face Normal</param>
        /// <param name="corbelBottomFace">Bottom Face of Corbel</param>
        /// <param name="bottomEdge">Given bottom edge to test</param>
        /// <param name="trapezoidFace">Output the trapezoid Face</param>
        /// <param name="topEdge">Output trapezoid top edge</param>
        /// <param name="leftEdge">Output trapezoid left edge</param>
        /// <param name="rightEdge">Output trapezoid right edge</param>
        /// <returns>True if there is a trapezoid face share the given bottom edge, otherwise false.</returns>
        private static bool IsTrapezoid(
            XYZ hostNormal, PlanarFace corbelBottomFace, Edge bottomEdge, 
            out PlanarFace trapezoidFace, out Edge topEdge, 
            out Edge leftEdge, out Edge rightEdge)
        {
            PlanarFace face1 = bottomEdge.get_Face(0) as PlanarFace;
            PlanarFace face2 = bottomEdge.get_Face(1) as PlanarFace;

            trapezoidFace = face1 == corbelBottomFace ? face2 : face1;

            EdgeArray trapezoidFaceEdges = trapezoidFace.EdgeLoops.get_Item(0);
            XYZ bottomEdgeDir = (bottomEdge.Evaluate(1.0) - bottomEdge.Evaluate(0.0)).Normalize();
            int bottomEdgeIndex = -1;
            topEdge = null;
            for (int i = 0; i < trapezoidFaceEdges.Size; i++)
            {
                Edge edge = trapezoidFaceEdges.get_Item(i);
                XYZ edgeDir = (edge.Evaluate(1.0) - edge.Evaluate(0.0)).Normalize();
                if (edgeDir.IsAlmostEqualTo(bottomEdgeDir) ||
                    edgeDir.IsAlmostEqualTo(-bottomEdgeDir))
                {
                    if (edge.Evaluate(0.0).IsAlmostEqualTo(bottomEdge.Evaluate(0.0)))
                    {
                        bottomEdge = edge;
                        bottomEdgeIndex = i;
                    }
                    else
                    {
                        topEdge = edge;
                    }
                }
            }

            leftEdge = trapezoidFaceEdges.get_Item((trapezoidFaceEdges.Size + bottomEdgeIndex - 1) % trapezoidFaceEdges.Size);
            rightEdge = trapezoidFaceEdges.get_Item((bottomEdgeIndex + 1) % trapezoidFaceEdges.Size);

            XYZ leftEdgeDir = (leftEdge.Evaluate(1.0) - leftEdge.Evaluate(0.0)).Normalize();
            bool isLeftEdgeVertical = false;
            if (leftEdgeDir.IsAlmostEqualTo(hostNormal) ||
                leftEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                isLeftEdgeVertical = true;
            }

            XYZ rightEdgeDir = (rightEdge.Evaluate(1.0) - rightEdge.Evaluate(0.0)).Normalize();
            bool rightEdgeIsVertical = false;
            if (rightEdgeDir.IsAlmostEqualTo(hostNormal) ||
                rightEdgeDir.IsAlmostEqualTo(-hostNormal))
            {
                rightEdgeIsVertical = true;
            }

            return isLeftEdgeVertical && !rightEdgeIsVertical;
        }
Esempio n. 35
0
 /// <summary>
 /// Compute the distance between two planar faces.
 /// </summary>
 /// <param name="face1">Face 1</param>
 /// <param name="face2">Face 2</param>
 /// <returns>Distance of the two planar faces</returns>
 private static double GetDistance(PlanarFace face1, PlanarFace face2)
 {
     BoundingBoxUV boxUV = face2.GetBoundingBox();
     UV center = (boxUV.Max + boxUV.Min) * 0.5;
     XYZ centerPt = face2.Evaluate(center);
     IntersectionResult result = face1.Project(centerPt);
     return face1.Project(centerPt).Distance;
 }
        /// <summary>
        /// Return an arbitrary point on a planar face,
        /// namely the midpoint of the first mesh triangle.
        /// </summary>
        XYZ PointOnFace( PlanarFace face )
        {
            XYZ p = new XYZ( 0, 0, 0 );
              Mesh mesh = face.Triangulate();

              for( int i = 0; i < mesh.NumTriangles; )
              {
            MeshTriangle triangle = mesh.get_Triangle( i );
            p += triangle.get_Vertex( 0 );
            p += triangle.get_Vertex( 1 );
            p += triangle.get_Vertex( 2 );
            p *= 0.3333333333333333;
            break;
              }
              return p;
        }
Esempio n. 37
0
 public virtual void Stream(PlanarFace face)
 {
     StreamFaceGeoometry(face);
 }
Esempio n. 38
0
        /// <summary>
        /// Create the CorbelFrame object with the given trapezoid face, corbel and its host information.
        /// </summary>
        /// <param name="corbel">Corbel instance</param>
        /// <param name="depthEdge">Depth Edge which is vertical with trapezoid face</param>
        /// <param name="leftEdge">Left edge of trapezoid</param>
        /// <param name="bottomEdge">Bottom edge of trapezoid</param>
        /// <param name="rightEdge">Right edge of trapezoid</param>
        /// <param name="topEdge">Top edge of trapezoid</param>
        /// <param name="revitDoc">Revit Document</param>
        /// <param name="trapezoidFace">Trapezoid Face</param>
        /// <param name="hostDepth">Corbel Host depth</param>
        /// <param name="hostTopCoverDistance">Corbel Host Top face cover distance</param>
        /// <returns>CorbelFrame object</returns>
        private static CorbelFrame ConstructCorbelFrame(
            FamilyInstance corbel, 
            Edge depthEdge, Edge leftEdge, Edge bottomEdge, Edge rightEdge, Edge topEdge, 
            Document revitDoc, PlanarFace trapezoidFace, 
            double hostDepth, double hostTopCoverDistance)
        {
            XYZ leftEdgeDir = (leftEdge.Evaluate(1.0) - leftEdge.Evaluate(0.0)).Normalize();
            XYZ leftEdgeV0 = leftEdge.Evaluate(0.0);
            Line leftEdgeLine = Line.get_Unbound(leftEdgeV0, leftEdgeDir);

            XYZ rightEdgeDir = (rightEdge.Evaluate(1.0) - rightEdge.Evaluate(0.0)).Normalize();
            XYZ rightEdgeV0 = rightEdge.Evaluate(0.0);
            Line rightEdgeLine = Line.get_Unbound(rightEdgeV0, rightEdgeDir);

            XYZ topEdgeDir = (topEdge.Evaluate(1.0) - topEdge.Evaluate(0.0)).Normalize();
            XYZ topEdgeV0 = topEdge.Evaluate(0.0);
            Line topEdgeLine = Line.get_Unbound(topEdgeV0, topEdgeDir);

            IntersectionResultArray intersections;
            topEdgeLine.Intersect(leftEdgeLine, out intersections);
            XYZ prevX = intersections.get_Item(0).XYZPoint;

            topEdgeLine.Intersect(rightEdgeLine, out intersections);
            XYZ nextX = intersections.get_Item(0).XYZPoint;

            XYZ edgeV0 = GetCommonVertex(bottomEdge, leftEdge);
            XYZ edgeV1 = GetCommonVertex(bottomEdge, rightEdge);

            Line topBoundLine = Line.get_Bound(nextX, prevX);
            Line leftBoundLine = Line.get_Bound(prevX, edgeV0);
            Line bottomBoundLine = Line.get_Bound(edgeV0, edgeV1);
            Line rightBoundLine = Line.get_Bound(edgeV1, nextX);

            Trapezoid profile = new Trapezoid(topBoundLine, leftBoundLine, bottomBoundLine, rightBoundLine);

            XYZ depthEdgeV0 = depthEdge.Evaluate(0.0);
            XYZ depthEdgeV1 = depthEdge.Evaluate(1.0);
            Line depthLine = null;
            if (depthEdgeV0.IsAlmostEqualTo(edgeV0))
            {
                depthLine = Line.get_Bound(depthEdgeV0, depthEdgeV1);
            }
            else if (depthEdgeV1.IsAlmostEqualTo(edgeV0))
            {
                 depthLine = Line.get_Bound(depthEdgeV1, depthEdgeV0);
            }

            CorbelFrame frame = new CorbelFrame(corbel, profile, depthLine, hostDepth, hostTopCoverDistance);

            return frame;
        }