FindMiddlePoint() public static méthode

Find the middle point of a profile. This method is used to find out middle point of the selected wall or floor.
public static FindMiddlePoint ( CurveArray curveArray ) : Autodesk.Revit.DB.XYZ
curveArray CurveArray the array of curve which form the profile
Résultat Autodesk.Revit.DB.XYZ
        /// <summary>
        /// Generate a Transform instance which as Transform property of BoundingBoxXYZ,
        /// when the user select a floor, this method will be called
        /// </summary>
        /// <returns>the reference of Transform, return null if it can't be generated</returns>
        Transform GenerateFloorTransform()
        {
            Transform transform = null;
            Floor     floor     = m_currentComponent as Floor;

            // First get the Analytical Model lines
            AnalyticalPanel model    = null;
            Document        document = floor.Document;
            AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);

            if (assocManager != null)
            {
                ElementId associatedElementId = assocManager.GetAssociatedElementId(floor.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalPanel)
                    {
                        model = associatedElement as AnalyticalPanel;
                    }
                }
            }
            if (null == model)
            {
                m_errorInformation = "Please select a structural floor.";
                return(transform);
            }

            CurveArray    curves    = m_project.Document.Application.Create.NewCurveArray();
            IList <Curve> curveList = model.GetOuterContour().ToList();

            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }

            if (null == curves || true == curves.IsEmpty)
            {
                m_errorInformation = "The program should never go here.";
                return(transform);
            }

            // Now I am sure I can create a transform instance.
            transform = Transform.Identity;

            // Third find the middle point of the floor and set it as Origin property.
            Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMiddlePoint(curves);
            transform.Origin = midPoint;

            // At last find out the directions of the created view, and set it as Basis property.
            Autodesk.Revit.DB.XYZ basisZ = XYZMath.FindFloorViewDirection(curves);
            Autodesk.Revit.DB.XYZ basisX = XYZMath.FindRightDirection(basisZ);
            Autodesk.Revit.DB.XYZ basisY = XYZMath.FindUpDirection(basisZ);

            transform.set_Basis(0, basisX);
            transform.set_Basis(1, basisY);
            transform.set_Basis(2, basisZ);
            return(transform);
        }
Exemple #2
0
        /// <summary>
        /// Generate a Transform instance which as Transform property of BoundingBoxXYZ,
        /// when the user select a floor, this method will be called
        /// </summary>
        /// <returns>the reference of Transform, return null if it can't be generated</returns>
        Transform GenerateFloorTransform()
        {
            Transform transform = null;
            Floor     floor     = m_currentComponent as Floor;

            // First get the Analytical Model lines
            AnalyticalModel model = floor.GetAnalyticalModel();

            if (null == model)
            {
                m_errorInformation = "Please select a structural floor.";
                return(transform);
            }

            CurveArray    curves    = m_project.Document.Application.Create.NewCurveArray();
            IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }

            if (null == curves || true == curves.IsEmpty)
            {
                m_errorInformation = "The program should never go here.";
                return(transform);
            }

            // Now I am sure I can create a transform instance.
            transform = Transform.Identity;

            // Third find the middle point of the floor and set it as Origin property.
            Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMiddlePoint(curves);
            transform.Origin = midPoint;

            // At last find out the directions of the created view, and set it as Basis property.
            Autodesk.Revit.DB.XYZ basisZ = XYZMath.FindFloorViewDirection(curves);
            Autodesk.Revit.DB.XYZ basisX = XYZMath.FindRightDirection(basisZ);
            Autodesk.Revit.DB.XYZ basisY = XYZMath.FindUpDirection(basisZ);

            transform.set_Basis(0, basisX);
            transform.set_Basis(1, basisY);
            transform.set_Basis(2, basisZ);
            return(transform);
        }