Example #1
0
        private void SetLength(bool rebarIsFamily)
        {
            double l = 0;

            if (rebarIsFamily)
            {
                Parameter lengthParam = ParametersSupport.GetParameter(elem, "Рзм.Длина");
                if (lengthParam == null)
                {
                    return;
                }
                l = lengthParam.AsDouble() * 304.8;
            }
            else
            {
                l = elem.LookupParameter("Длина стержня").AsDouble() * 304.8;
            }
            double roundLength = 5 * Math.Round(l / 5, MidpointRounding.AwayFromZero);

            lengthMm = roundLength;
        }
Example #2
0
        /// <summary>
        /// Заполняет параметры BDS_RebarHostId, BDS_RebarUniqueHostId, Мрк.МаркаКонструкции, Рзм.ТолщинаОсновы. В случае нескольких элемеетов знчения записываются через разделитель "|"
        /// </summary>
        /// <param name="rebar"></param>
        /// <param name="hostElem"></param>
        public static string WriteHostInfoSingleRebar(Autodesk.Revit.ApplicationServices.Application revitApp, CategorySet rebarCatSet, Element rebar, List <Element> hostElements)
        {
            if (Settings.UseHostId)
            {
                HashSet <string> hostIds = new HashSet <string>();
                foreach (Element hostElem in hostElements)
                {
                    ElementId hostId = hostElem.Id;
                    string    tempid = hostId.IntegerValue.ToString();
                    hostIds.Add(tempid);
                }
                Parameter rebarHostIdParam = RebarParametrisation.ParametersSupport.CheckAndAddSharedParameter(rebar, revitApp, rebarCatSet, "BDS_RebarHostId", BuiltInParameterGroup.INVALID, true);
                string    hostIdString     = ConvertHashsetToString(hostIds);
                rebarHostIdParam.Set(hostIdString);
            }
            if (Settings.UseUniqueHostId)
            {
                HashSet <string> hostUniqIds = new HashSet <string>();
                foreach (Element hostElem in hostElements)
                {
                    hostUniqIds.Add(hostElem.UniqueId);
                }

                Parameter rebarHostUniqueIdParam = RebarParametrisation.ParametersSupport.CheckAndAddSharedParameter(rebar, revitApp, rebarCatSet, "BDS_RebarUniqueHostId", BuiltInParameterGroup.INVALID, true);
                string    hostUniqueId           = ConvertHashsetToString(hostUniqIds);
                rebarHostUniqueIdParam.Set(hostUniqueId);
            }

            if (Settings.UseHostMark)
            {
                HashSet <string> hostMarks = new HashSet <string>();
                foreach (Element hostElem in hostElements)
                {
                    Parameter hostMarkParam = hostElem.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                    string    tempMark      = hostMarkParam.AsString();
                    if (string.IsNullOrEmpty(tempMark))
                    {
                        return("Не заполнена марка у конструкции: " + hostElem.Id.IntegerValue.ToString() + " в файле " + hostElem.Document.Title);
                    }
                    else
                    {
                        hostMarks.Add(tempMark);
                    }
                }

                string hostMark = ConvertHashsetToString(hostMarks);
                ParametersSupport.TryWriteParameter(rebar, "Мрк.МаркаКонструкции", hostMark);
            }

            if (Settings.UseHostThickness)
            {
                Parameter thicknessRebarParam = rebar.LookupParameter("Рзм.ТолщинаОсновы");
                if (thicknessRebarParam != null)
                {
                    if (!thicknessRebarParam.IsReadOnly)
                    {
                        HashSet <double> hostWidths = new HashSet <double>();

                        foreach (Element hostElem in hostElements)
                        {
                            if (hostElem is Wall)
                            {
                                Wall hostWall = hostElem as Wall;
                                hostWidths.Add(hostWall.Width);
                            }
                            if (hostElem is Floor)
                            {
                                Floor     hostFloor      = hostElem as Floor;
                                Parameter thicknessParam = hostFloor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM);
                                if (thicknessParam == null)
                                {
                                    thicknessParam = hostFloor.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
                                    if (thicknessParam == null)
                                    {
                                        hostWidths.Add(0);
                                    }
                                }
                                if (thicknessParam != null)
                                {
                                    hostWidths.Add(thicknessParam.AsDouble());
                                }
                            }
                        }

                        double hostWidth = 0;
                        if (hostWidths.Count == 1)
                        {
                            hostWidth = hostWidths.First();
                        }
                        thicknessRebarParam.Set(hostWidth);
                    }
                }
            }
            return(string.Empty);
        }
Example #3
0
        public MyRebar(Element Elem)
        {
            IsValid = false;
            //IsCancel = false;
            elem = Elem;

            Parameter rebarIsFamilyParam = ParametersSupport.GetParameter(elem, "Арм.ВыполненаСемейством");

            if (rebarIsFamilyParam == null)
            {
                return;
            }

            bool rebarIsFamily = rebarIsFamilyParam.AsInteger() == 1;

            Parameter rebarClassParam = ParametersSupport.GetParameter(elem, "Арм.КлассЧисло");

            if (rebarClassParam == null)
            {
                return;
            }
            rebarClass = rebarClassParam.AsDouble();



            this.SetLength(rebarIsFamily);


            if (rebarIsFamily)
            {
                Parameter countParam = ParametersSupport.GetParameter(elem, "О_Количество");
                if (countParam == null)
                {
                    return;
                }
                count = countParam.AsDouble();

                if (rebarClass > 0)
                {
                    Parameter diamParam = ParametersSupport.GetParameter(elem, "Рзм.Диаметр");
                    if (diamParam == null)
                    {
                        return;
                    }
                    double diameterFoots = diamParam.AsDouble();
                    diameterMm     = (int)(diameterFoots * 304.8);
                    WeightPerMeter = GetWeightPerMeter(diameterMm);
                }
                else
                {
                    Parameter WeightPerMeterParam = ParametersSupport.GetParameter(elem, "О_МассаПогМетра");
                    if (WeightPerMeterParam == null)
                    {
                        return;
                    }
                    WeightPerMeter = WeightPerMeterParam.AsDouble();
                }
            }
            else
            {
                count = elem.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS).AsInteger();

                Parameter diamParam = ParametersSupport.GetParameter(elem, "Диаметр стержня");
                if (diamParam == null)
                {
                    return;
                }
                double diameterFoots = diamParam.AsDouble();
                double d2            = diameterFoots * 304.8;
                double d3            = Math.Round(d2);

                diameterMm     = (int)d3;
                WeightPerMeter = GetWeightPerMeter(diameterMm);
            }

            double WeightOnePcs = 0;
            double countPM      = 0;

            Parameter asSummLengthParam = ParametersSupport.GetParameter(elem, "Рзм.ПогМетрыВкл");

            if (asSummLengthParam == null)
            {
                return;
            }
            bool calcAsSummLength = (asSummLengthParam.AsInteger() == 1) && (!rebarIsFamily);

            if (calcAsSummLength)
            {
                WeightOnePcs = WeightPerMeter;
                overlapCoeff = 1;
                if (!rebarIsFamily && rebarClass > 0)
                {
                    double    concreteClass      = 0;
                    Parameter concreteClassParam = ParametersSupport.GetParameter(elem, "Арм.КлассБетона");
                    if (concreteClassParam == null)
                    {
                        concreteClass = Settings.DefaultConcreteClass;
                    }
                    else
                    {
                        concreteClass = concreteClassParam.AsDouble();
                    }

                    double Rs  = GetRs();
                    double Rbt = GetRbt(concreteClass);

                    double mm32 = 1;
                    if (diameterMm > 32)
                    {
                        mm32 = 0.9;
                    }

                    overlapCoeff = 1 + 0.001 * Math.Ceiling((1.2 * Rs * diameterMm) / (2.5 * mm32 * Rbt * 4 * 11.75));
                }

                countPM = 0.1 * Math.Round(lengthMm * count * overlapCoeff / 100, MidpointRounding.AwayFromZero);
            }
            else
            {
                double m1 = WeightPerMeter * lengthMm;
                double m2 = Math.Ceiling(m1);
                double m3 = 0.001 * m2;
                double m4 = Math.Round(m3, 3, MidpointRounding.AwayFromZero);
                WeightOnePcs = m4;
                countPM      = count;
                overlapCoeff = 1;
            }

            double wf1 = countPM * WeightOnePcs;
            double wf2 = 10000 * wf1;
            double wf3 = Math.Round(wf2);
            double wf4 = wf3 * 0.01;
            double wf5 = Math.Round(wf4, MidpointRounding.AwayFromZero);
            double wf6 = 0.01 * wf5;

            weightFinal = wf6;

            IsValid = true;
        }
Example #4
0
        public string Start(Document doc, Autodesk.Revit.ApplicationServices.Application revitApp, Transform linkTransform, out List <Element> concreteElements)
        {
            haveConcreteClass    = true;
            defaultConcreteClass = 25;
            Category rebarCat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Rebar);

            rebarCatSet = revitApp.Create.NewCategorySet();
            rebarCatSet.Insert(rebarCat);
            ElementId rebarCategoryId = new ElementId(BuiltInCategory.OST_Rebar);

            //собираю арматуру
            List <Element> rebarsAll = new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Rebar)
                                       .ToElements()
                                       .ToList();

            List <Rebar> StandartRebars = new FilteredElementCollector(doc)
                                          .OfClass(typeof(Rebar))
                                          .Cast <Rebar>()
                                          .ToList();

            List <RebarInSystem> RebarsInSystem = new FilteredElementCollector(doc)
                                                  .OfClass(typeof(RebarInSystem))
                                                  .Cast <RebarInSystem>()
                                                  .ToList();

            List <FamilyInstance> rebarsIfcAll = new FilteredElementCollector(doc)
                                                 .OfClass(typeof(FamilyInstance))
                                                 .OfCategory(BuiltInCategory.OST_Rebar)
                                                 .Cast <FamilyInstance>()
                                                 .ToList();

            List <FamilyInstance> rebarsIfcSingle = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(FamilyInstance))
                                                    .OfCategory(BuiltInCategory.OST_Rebar)
                                                    .Cast <FamilyInstance>()
                                                    .Where(i => i.SuperComponent == null)
                                                    .ToList();

            List <FamilyInstance> rebarsIfcNested = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(FamilyInstance))
                                                    .OfCategory(BuiltInCategory.OST_Rebar)
                                                    .Cast <FamilyInstance>()
                                                    .Where(i => i.SuperComponent != null)
                                                    .ToList();

            List <Element> rebarsNotNested = new List <Element>();

            rebarsNotNested.AddRange(StandartRebars);
            rebarsNotNested.AddRange(RebarsInSystem);
            rebarsNotNested.AddRange(rebarsIfcSingle);


            //сгруппирую вложенные семейства по родительским
            foreach (FamilyInstance nestedRebar in rebarsIfcNested)
            {
                FamilyInstance parentFamily = ParentFamilyContainer.GetMainParentFamily(nestedRebar);
                int            parentId     = parentFamily.Id.IntegerValue;
                if (parentFamiliesBase.ContainsKey(parentId))
                {
                    parentFamiliesBase[parentId].childFamilies.Add(nestedRebar);
                }
                else
                {
                    List <FamilyInstance> fams = new List <FamilyInstance>()
                    {
                        nestedRebar
                    };
                    ParentFamilyContainer pfc = new ParentFamilyContainer(parentFamily, nestedRebar);
                    parentFamiliesBase.Add(parentId, pfc);
                }
            }



            //собираю бетонные элементы
            CategoriesSupport catSupport          = new CategoriesSupport(revitApp, doc);
            List <ElementId>  concreteCategodyIds = catSupport.GetConcreteCategodyIds();
            View defaultView3d = ViewSupport.GetDefaultView(doc);

            concreteElements = new FilteredElementCollector(doc, defaultView3d.Id)
                               .WhereElementIsNotElementType()
                               .Where(x => x.Category != null)
                               .Where(x => x.Category.Id != rebarCategoryId)
                               .Where(x => concreteCategodyIds.Contains(x.Category.Id))
                               .Where(x => Intersection.ContainsSolids(x))
                               .Where(x => Intersection.CheckElementIsConcrete(x))
                               .ToList();

            if (Settings.UseHostMark && MainElementsForLibFile == null)
            {
                string errorIds = "";
                foreach (Element elem in concreteElements)
                {
                    Parameter markParam = elem.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);

                    string tempMark = markParam.AsString();
                    if (string.IsNullOrEmpty(tempMark))
                    {
                        errorIds += elem.Id.IntegerValue.ToString() + "; ";
                    }
                }
                if (errorIds != "")
                {
                    string msg = "Не заполнена Марка у конструкций: " + errorIds;
                    return(msg);
                }
            }

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Rebar BDS");

                //заполняю массу, длину и диаметр
                foreach (Element elem in rebarsAll)
                {
                    Parameter p = ParametersSupport.GetParameter(elem, "Орг.ИзделиеТипПодсчета");
                    if (p == null)
                    {
                        continue;            //отсеиваем левую арматуру без параметров
                    }
                    int c = p.AsInteger();
                    if (c < 1 || c > 5)
                    {
                        continue;                 //отсеиваем каркасы и закладные детали
                    }
                    MyRebar myrebar = new MyRebar(elem);

                    if (!myrebar.IsValid)
                    {
                        continue;
                    }

                    if (Settings.UseRebarWeight)
                    {
                        Parameter paramWeight = ParametersSupport.CheckAndAddSharedParameter(elem, revitApp, rebarCatSet, "BDS_Weight", BuiltInParameterGroup.INVALID, true);
                        paramWeight.Set(myrebar.weightFinal);
                    }

                    if (Settings.UseRebarLength)
                    {
                        Parameter paramLength = ParametersSupport.CheckAndAddSharedParameter(elem, revitApp, rebarCatSet, "BDS_Length", BuiltInParameterGroup.INVALID, true);
                        paramLength.Set(myrebar.lengthMm);
                    }

                    if (Settings.UseRebarDiameter)
                    {
                        Parameter diamParam = ParametersSupport.CheckAndAddSharedParameter(elem, revitApp, rebarCatSet, "BDS_Diameter", BuiltInParameterGroup.INVALID, true);
                        diamParam.Set(myrebar.diameterMm);
                    }
                }

                doc.Regenerate();


                //заполняю марку основы для не вложенных стержней
                foreach (Element rebarNotNested in rebarsNotNested)
                {
                    ElementId      hostId    = null;
                    List <Element> hostElems = null;

                    if (MainElementsForLibFile != null) //если основной бетонный элемент задан принудительно
                    {
                        hostElems = MainElementsForLibFile;
                    }
                    else
                    {
                        if (rebarNotNested is Rebar)
                        {
                            hostId = (rebarNotNested as Rebar).GetHostId();
                        }
                        if (rebarNotNested is RebarInSystem)
                        {
                            hostId = (rebarNotNested as RebarInSystem).GetHostId();
                        }
                        if (rebarNotNested is FamilyInstance)
                        {
                            Element tempHost = Intersection.GetHostElementForIfcRebar(doc, defaultView3d, rebarNotNested, concreteElements, linkTransform);
                            if (tempHost == null)
                            {
                                rebarWithoutHost.Add(rebarNotNested);
                                continue;
                            }
                            hostId = tempHost.Id;
                        }

                        if (hostId == null)
                        {
                            rebarWithoutHost.Add(rebarNotNested);
                            continue;
                        }
                        Element hostElem = doc.GetElement(hostId);
                        hostElems = new List <Element>()
                        {
                            hostElem
                        };
                    }

                    string msg = ParametersSupport.WriteHostInfoSingleRebar(revitApp, rebarCatSet, rebarNotNested, hostElems);
                    if (msg != string.Empty)
                    {
                        return(msg);
                    }
                }

                //заполняю марку основы для стержней, вложенных в сложные семейства
                foreach (var kvp in parentFamiliesBase)
                {
                    ParentFamilyContainer pfc          = kvp.Value;
                    FamilyInstance        parentFamily = pfc.parentFamily;

                    Dictionary <int, Element> hostElemsBase = new Dictionary <int, Element>();

                    List <Element> mainHostElems = null;

                    if (MainElementsForLibFile != null)  //если основной бетонный элемент задан принудительно
                    {
                        mainHostElems = MainElementsForLibFile;
                    }
                    else
                    {
                        if (parentFamily.Host is Wall || parentFamily.Host is Floor) //родительское семейство - на основе стены или пола, можно легко получить основу
                        {
                            Element mainHostElem = parentFamily.Host;
                            mainHostElems = new List <Element>()
                            {
                                mainHostElem
                            };
                        }
                        else
                        {
                            foreach (FamilyInstance nestedRebar in pfc.childFamilies)
                            {
                                Element hostElem = Intersection.GetHostElementForIfcRebar(doc, defaultView3d, nestedRebar, concreteElements, linkTransform);
                                if (hostElem == null)
                                {
                                    continue;
                                }
                                int hostElemId = hostElem.Id.IntegerValue;
                                if (!hostElemsBase.ContainsKey(hostElemId))
                                {
                                    hostElemsBase.Add(hostElemId, hostElem);
                                }
                            }
                            if (hostElemsBase.Count == 0)
                            {
                                rebarWithoutHost.Add(parentFamily);
                                continue;
                            }

                            if (hostElemsBase.Count == 1)
                            {
                                Element mainHostElem = hostElemsBase.First().Value;
                                mainHostElems = new List <Element>()
                                {
                                    mainHostElem
                                };
                            }
                            if (hostElemsBase.Count > 1)
                            {
                                List <Element> hosts        = hostElemsBase.Values.ToList();
                                View           defaultView  = ViewSupport.GetDefaultView(doc);
                                Element        mainHostElem = Intersection.GetBottomElement(hosts, defaultView);
                                mainHostElems = new List <Element>()
                                {
                                    mainHostElem
                                };
                            }
                        }
                    }

                    if (Settings.UseHostMark)
                    {
                        string hostMark = "";
                        foreach (Element mainHostElem in mainHostElems)
                        {
                            Parameter hostMarkParam = mainHostElem.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                            string    tempHostMark  = hostMarkParam.AsString();
                            if (string.IsNullOrEmpty(tempHostMark))
                            {
                                return("Не заполнена марка у конструкции: " + mainHostElem.Id.IntegerValue.ToString() + " в файле " + mainHostElem.Document.Title);
                            }

                            if (hostMark != "")
                            {
                                hostMark += "|";
                            }
                            hostMark += tempHostMark;
                        }
                        ParametersSupport.TryWriteParameter(parentFamily, "Мрк.МаркаКонструкции", hostMark);
                    }

                    foreach (FamilyInstance nestedRebar in pfc.childFamilies)
                    {
                        ParametersSupport.WriteHostInfoSingleRebar(revitApp, rebarCatSet, nestedRebar, mainHostElems);
                    }
                }


                t.Commit();
            }
            return(string.Empty);
        }