示例#1
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);
        }
示例#2
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);
        }