예제 #1
0
        /// <summary>
        /// Get two vectors, which indicate some edge direction which contain given point,
        /// set the given point as the start point, the other end point of the edge as end
        /// </summary>
        /// <param name="point">a point of the swept profile</param>
        /// <returns>two vectors indicate edge direction</returns>
        protected List <Autodesk.Revit.DB.XYZ> GetRelatedVectors(Autodesk.Revit.DB.XYZ point)
        {
            // Initialize the return vector list.
            List <Autodesk.Revit.DB.XYZ> vectors = new List <Autodesk.Revit.DB.XYZ>();

            // Get all the edge which contain this point.
            // And get the vector from this point to another point
            foreach (Line line in m_edges)
            {
                if (GeomUtil.IsEqual(point, line.GetEndPoint(0)))
                {
                    Autodesk.Revit.DB.XYZ vector = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0));
                    vectors.Add(vector);
                }
                if (GeomUtil.IsEqual(point, line.GetEndPoint(1)))
                {
                    Autodesk.Revit.DB.XYZ vector = GeomUtil.SubXYZ(line.GetEndPoint(0), line.GetEndPoint(1));
                    vectors.Add(vector);
                }
            }

            // only two vector(direction) should be found
            if (2 != vectors.Count)
            {
                throw new Exception("a point on swept profile should have only two direction.");
            }

            return(vectors);
        }
예제 #2
0
        /// <summary>
        /// Get the swept profile(face) of the host object(family instance)
        /// </summary>
        /// <param name="solid">the solid reference</param>
        /// <returns>the swept profile</returns>
        private Face GetSweptProfileFace(Solid solid)
        {
            // Get a point on the swept profile from all points in solid
            Autodesk.Revit.DB.XYZ refPoint = new Autodesk.Revit.DB.XYZ(); // the point on swept profile
            foreach (Edge edge in solid.Edges)
            {
                List <XYZ> points = edge.Tessellate() as List <XYZ>; //get end points of the edge
                if (2 != points.Count)                               // make sure all edges are lines
                {
                    throw new Exception("All edge should be line.");
                }

                // get two points of the edge. All points in solid should be transform first
                Autodesk.Revit.DB.XYZ first  = Transform(points[0]); // start point of edge
                Autodesk.Revit.DB.XYZ second = Transform(points[1]); // end point of edge

                // some edges should be parallelled with the driving line,
                // and the start point of that edge should be the wanted point
                Autodesk.Revit.DB.XYZ edgeVector = GeomUtil.SubXYZ(second, first);
                if (GeomUtil.IsSameDirection(edgeVector, m_drivingVector))
                {
                    refPoint = first;
                    break;
                }
                if (GeomUtil.IsOppositeDirection(edgeVector, m_drivingVector))
                {
                    refPoint = second;
                    break;
                }
            }

            // Find swept profile(face)
            Face sweptFace = null; // define the swept face

            foreach (Face face in solid.Faces)
            {
                if (null != sweptFace)
                {
                    break;
                }
                // the swept face should be perpendicular with the driving line
                if (!GeomUtil.IsVertical(face, m_drivingLine, m_transform, null))
                {
                    continue;
                }
                // use the gotted point to get the swept face
                foreach (Autodesk.Revit.DB.XYZ point in face.Triangulate().Vertices)
                {
                    Autodesk.Revit.DB.XYZ pnt = Transform(point); // all points in solid should be transform
                    if (GeomUtil.IsEqual(refPoint, pnt))
                    {
                        sweptFace = face;
                        break;
                    }
                }
            }

            return(sweptFace);
        }
예제 #3
0
 int IComparer <Autodesk.Revit.DB.XYZ> .Compare(Autodesk.Revit.DB.XYZ first, Autodesk.Revit.DB.XYZ second)
 {
     // first compare z coordinate, then y coordinate, at last x coordinate
     if (GeomUtil.IsEqual(first.Z, second.Z))
     {
         if (GeomUtil.IsEqual(first.Y, second.Y))
         {
             if (GeomUtil.IsEqual(first.X, second.X))
             {
                 return(0);
             }
             return((first.X > second.X) ? 1 : -1);
         }
         return((first.Y > second.Y) ? 1 : -1);
     }
     return((first.Z > second.Z) ? 1 : -1);
 }