public static FindUpDirection ( Autodesk viewDirection ) : Autodesk.Revit.DB.XYZ | ||
viewDirection | Autodesk | the view direction vector |
return | 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 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); }
/// <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); }
/// <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); }