A object to help locating with geometry data.
Example #1
0
        /// <summary>
        /// Located the buttom of a slab object.
        /// </summary>
        /// <param name="floor">A floor object.</param>
        /// <param name="bubbleEnd">The bubble end of new reference plane.</param>
        /// <param name="freeEnd">The free end of new reference plane.</param>
        /// <param name="thirdPnt">The third point of new reference plane.</param>
        private void LocateSlab(Floor floor, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ thirdPnt)
        {
            //Obtain the geometry data of the floor.
            GElement geometry   = floor.get_Geometry(m_options);
            Face     buttomFace = null;

            //foreach (GeometryObject go in geometry.Objects)
            IEnumerator <GeometryObject> Objects = geometry.GetEnumerator();

            while (Objects.MoveNext())
            {
                GeometryObject go = Objects.Current;

                Solid solid = go as Solid;
                if (null == solid)
                {
                    continue;
                }
                else
                {
                    //Get the bottom face of this floor.
                    buttomFace = GeoHelper.GetBottomFace(solid.Faces);
                }
            }

            Mesh mesh = buttomFace.Triangulate();

            GeoHelper.Distribute(mesh, ref bubbleEnd, ref freeEnd, ref thirdPnt);
        }
Example #2
0
        /// <summary>
        /// Located the exterior of a wall object.
        /// </summary>
        /// <param name="wall">A wall object</param>
        /// <param name="bubbleEnd">The bubble end of new reference plane.</param>
        /// <param name="freeEnd">The free end of new reference plane.</param>
        /// <param name="cutVec">The cut vector of new reference plane.</param>
        private void LocateWall(Wall wall, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ cutVec)
        {
            LocationCurve location  = wall.Location as LocationCurve;
            Curve         locaCurve = location.Curve;

            //Not work for wall without location.
            if (null == locaCurve)
            {
                throw new Exception("This wall has no location.");
            }

            //Not work for arc wall.
            Line line = locaCurve as Line;

            if (null == line)
            {
                throw new Exception("Just work for straight wall.");
            }

            //Calculate offset by law of cosines.
            double halfThickness = wall.Width / 2;
            double length        = GeoHelper.GetLength(locaCurve.GetEndPoint(0), locaCurve.GetEndPoint(1));
            double xAxis         = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).X, locaCurve.GetEndPoint(1).X);
            double yAxis         = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).Y, locaCurve.GetEndPoint(1).Y);

            double xOffset = yAxis * halfThickness / length;
            double yOffset = xAxis * halfThickness / length;

            if (locaCurve.GetEndPoint(0).X < locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
            {
                xOffset = -xOffset;
            }
            if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y > locaCurve.GetEndPoint(1).Y)
            {
                yOffset = -yOffset;
            }
            if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X &&
                locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
            {
                xOffset = -xOffset;
                yOffset = -yOffset;
            }

            //Three necessary parameters for generate a reference plane.
            bubbleEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(0).X + xOffset,
                                                  locaCurve.GetEndPoint(0).Y + yOffset, locaCurve.GetEndPoint(0).Z);
            freeEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(1).X + xOffset,
                                                locaCurve.GetEndPoint(1).Y + yOffset, locaCurve.GetEndPoint(1).Z);
            cutVec = new Autodesk.Revit.DB.XYZ(0, 0, 1);
        }