/// <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 GenerateDuctTransform() { Transform transform = null; Duct instance = m_currentComponent as Duct; // 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(); //var startOffset2 = instance.get_Parameter(BuiltInParameter.RBS_DUCT_SLOPE); double ductSlope = instance.get_Parameter(BuiltInParameter.RBS_DUCT_SLOPE).AsDouble(); if (ductSlope != 0) { m_errorInformation = "Please select a horizontal duct."; return(transform); } int nDucts = 0; int nCurves = 0; LocationCurve lc = instance.Location as LocationCurve; Debug.Assert(null != lc, "expected duct to have valid location curve."); if (null != lc) { ++nCurves; Curve c = lc.Curve; // 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 = c.GetEndPoint(0); Autodesk.Revit.DB.XYZ endPoint = c.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 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); }