Ejemplo n.º 1
0
        /// <summary>
        /// Creates trusses along a specific ridge edge and stores them on a list of truss info
        /// </summary>
        /// <param name="currentRidgeEdgeInfo">The specific edge ridge to create trusses</param>
        /// <param name="doc">The target document to create the trusses</param>
        /// <param name="tType">The target truss type to be used on creation</param>
        /// <returns>The list of info of the created trusses</returns>
        private IList <TrussInfo> CreateTrussInfoList(EdgeInfo currentRidgeEdgeInfo, Document doc, TrussType tType)
        {
            IList <TrussInfo> trussInfoList = new List <TrussInfo>();

            if (currentRidgeEdgeInfo.RoofLineType == RoofLineType.RidgeSinglePanel || currentRidgeEdgeInfo.RoofLineType == RoofLineType.Ridge)
            {
                Line currentRidgeLineShortenedBySupports = currentRidgeEdgeInfo.Curve as Line;

                if (currentRidgeLineShortenedBySupports == null)
                {
                    return(trussInfoList);
                }

                IList <EdgeInfo> startConditions = currentRidgeEdgeInfo.GetEndConditions(0);
                IList <EdgeInfo> endConditions   = currentRidgeEdgeInfo.GetEndConditions(1);

                currentRidgeLineShortenedBySupports = ShortenRidgeIfNecessary(currentRidgeLineShortenedBySupports, startConditions, endConditions);

                Tuple <int, double> iterations = Utils.Utils.EstabilishIterations(currentRidgeLineShortenedBySupports.ApproximateLength, trussDistance);
                int    numPoints = iterations.Item1;
                double distance  = iterations.Item2;

                for (int i = 0; i <= numPoints; i++)
                {
                    double    currentParam        = i * distance;
                    XYZ       currentPointOnRidge = currentRidgeLineShortenedBySupports.Evaluate(currentRidgeLineShortenedBySupports.GetEndParameter(0) + currentParam, false);
                    TrussInfo currentTrussInfo    = TrussInfo.BuildTrussAtRidge(currentPointOnRidge, currentRidgeEdgeInfo, null);

                    if (currentTrussInfo != null)
                    {
                        SketchPlane stkP = SketchPlane.Create(doc, currentRidgeEdgeInfo.CurrentRoof.LevelId);

                        double levelHeight = currentRidgeEdgeInfo.GetCurrentRoofHeight();

                        XYZ   firstPoint   = new XYZ(currentTrussInfo.FirstPoint.X, currentTrussInfo.FirstPoint.Y, levelHeight);
                        XYZ   secondPoint  = new XYZ(currentTrussInfo.SecondPoint.X, currentTrussInfo.SecondPoint.Y, levelHeight);
                        Truss currentTruss = Truss.Create(doc, tType.Id, stkP.Id, Line.CreateBound(firstPoint, secondPoint));

                        currentTruss.get_Parameter(BuiltInParameter.TRUSS_HEIGHT).Set(currentTrussInfo.Height);
                        trussInfoList.Add(currentTrussInfo);
                    }
                    #region DEBUG ONLY
                    else
                    {
#if DEBUG
                        FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol;
                        fs.Activate();
                        doc.Create.NewFamilyInstance(currentPointOnRidge, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
#endif
                    }
                    #endregion
                }
            }

            return(trussInfoList);
        }