public static FindMidPoint ( Autodesk first, Autodesk second ) : Autodesk.Revit.DB.XYZ | ||
first | Autodesk | the start point of the line |
second | Autodesk | the end point of the line |
Результат | Autodesk.Revit.DB.XYZ |
/// <summary> /// Generate a Transform instance which as Transform property of BoundingBoxXYZ, /// when the user select a wall, this method will be called /// </summary> /// <returns>the reference of Transform, return null if it can't be generated</returns> Transform GenerateWallTransform() { Transform transform = null; Wall wall = m_currentComponent as Wall; // Because the architecture wall and curtain wall don't have analytical Model lines. // So Use Location property of wall object is better choice. // First get the location line of the wall LocationCurve location = wall.Location as LocationCurve; Line locationLine = location.Curve as Line; transform = Transform.Identity; // Second find the middle point of the wall and set it as Origin property. XYZ mPoint = XYZMath.FindMidPoint(locationLine.GetEndPoint(0), locationLine.GetEndPoint(1)); // midPoint is mid point of the wall location, but not the wall's. // The different is the elevation of the point. Then change it. Autodesk.Revit.DB.XYZ midPoint = new XYZ(mPoint.X, mPoint.Y, mPoint.Z + GetWallMidOffsetFromLocation(wall)); 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.FindDirection(locationLine.GetEndPoint(0), locationLine.GetEndPoint(1)); 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); }
/// <summary> /// Generate a Transform instance which as Transform property of BoundingBoxXYZ, /// when the user select a beam, this method will be called /// </summary> /// <returns>the reference of Transform, return null if it can't be generated</returns> Transform GenerateBeamTransform() { Transform transform = null; FamilyInstance instance = m_currentComponent as FamilyInstance; // First check whether the beam is horizontal. // In order to predigest the calculation, only allow it to be horizontal double startOffset = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble(); double endOffset = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).AsDouble(); if (-PRECISION > startOffset - endOffset || PRECISION < startOffset - endOffset) { m_errorInformation = "Please select a horizontal beam."; return(transform); } // Second get the Analytical Model line. AnalyticalModel model = instance.GetAnalyticalModel(); if (null == model) { m_errorInformation = "The selected beam doesn't have Analytical Model line."; return(transform); } Curve curve = model.GetCurve(); if (null == curve) { 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 line and set it as Origin property. Autodesk.Revit.DB.XYZ startPoint = curve.GetEndPoint(0); Autodesk.Revit.DB.XYZ endPoint = curve.GetEndPoint(1); Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMidPoint(startPoint, endPoint); 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.FindDirection(startPoint, endPoint); 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); }