SubXYZ() public static method

Subtraction of two points(or vectors), get a new vector
public static SubXYZ ( Autodesk p1, Autodesk p2 ) : Autodesk.Revit.DB.XYZ
p1 Autodesk The first point(vector)
p2 Autodesk The second point(vector)
return Autodesk.Revit.DB.XYZ
示例#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 edges 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 vectors(directions) should be found
            if (2 != vectors.Count)
            {
                throw new Exception("A point on swept profile should have only two directions.");
            }

            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("Each edge should be a line.");
                }

                // get two points of the edge. All points in solid should be transformed 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 paralleled 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 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 transformed
                    if (GeomUtil.IsEqual(refPoint, pnt))
                    {
                        sweptFace = face;
                        break;
                    }
                }
            }

            return(sweptFace);
        }
示例#3
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="element">The host object, must be family instance</param>
        public GeometrySupport(FamilyInstance element)
        {
            // get the geometry element of the selected element
            Autodesk.Revit.DB.GeometryElement geoElement = element.get_Geometry(new Options());
            IEnumerator <GeometryObject>      Objects    = geoElement.GetEnumerator();

            //if (null == geoElement || 0 == geoElement.Objects.Size)
            if (null == geoElement || !Objects.MoveNext())
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            SweptProfile swProfile = element.GetSweptProfile();

            if (swProfile == null || !(swProfile.GetDrivingCurve() is Line))
            {
                throw new Exception("The selected element driving curve is not a line.");
            }

            // get the driving path and vector of the beam or column
            Line line = swProfile.GetDrivingCurve() as Line;

            if (null != line)
            {
                m_drivingLine   = line; // driving path
                m_drivingVector = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0));
                m_drivingLength = m_drivingVector.GetLength();
            }

            //get the geometry object
            //foreach (GeometryObject geoObject in geoElement.Objects)
            Objects.Reset();
            while (Objects.MoveNext())
            {
                GeometryObject geoObject = Objects.Current;

                //get the geometry instance which contains the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    //foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    IEnumerator <GeometryObject> Objects1 = instance.SymbolGeometry.GetEnumerator();
                    while (Objects1.MoveNext())
                    {
                        GeometryObject o = Objects1.Current;

                        // get the solid of beam of column
                        Solid solid = o as Solid;

                        // do some checks.
                        if (null == solid)
                        {
                            continue;
                        }
                        if (0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }

                        m_solid = solid;
                        //get the transform value of instance
                        m_transform = instance.Transform;

                        // Get the swept profile curves information
                        if (!GetSweptProfile(solid))
                        {
                            throw new Exception("Can't get the swept profile curves.");
                        }
                        break;
                    }
                }
            }

            // do some checks about profile curves information
            if (null == m_edges)
            {
                throw new Exception("Can't get the geometry edge information.");
            }
            if (4 != m_points.Count)
            {
                throw new Exception("The sample only works for rectangle beam or column.");
            }
        }