Esempio n. 1
0
        public void CreateFilterRule3dGrid(Document doc, out ParameterFilterElement parameterFilterElement)
        {
            if (CheckFilter(doc, out parameterFilterElement))
            {
            }
            else
            {
                List <ElementId> categories = new List <ElementId>();
                categories.Add(new ElementId(BuiltInCategory.OST_GenericModel));
                List <FilterRule> filterRules = new List <FilterRule>();
                // Create filter element assocated to the input categories
                parameterFilterElement = ParameterFilterElement.Create(doc, "Grid 3D", categories);
                var            collector      = (from x in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).OfClass(typeof(FamilyInstance)).Cast <FamilyInstance>() where x.Name.Contains("650mm Bubble - Single") select x).ToList();
                FamilyInstance familyInstance = collector.First();

                if (familyInstance != null)
                {
                    ElementId sharedParamId = familyInstance.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).Id;

                    filterRules.Add(ParameterFilterRuleFactory.CreateContainsRule(sharedParamId, "3D Grid", true));
                }

                parameterFilterElement.SetRules(filterRules);
                // Apply filter to view
                //doc.ActiveView.AddFilter(parameterFilterElement.Id);
                //doc.ActiveView.SetFilterVisibility(parameterFilterElement.Id, false);
            }
        }
Esempio n. 2
0
        private IList <ElementId> CreateFiltersIfMissing(Document doc)
        {
            bool[] array = new bool[4];
            FilteredElementCollector val = new FilteredElementCollector(doc);

            val.OfClass(typeof(ParameterFilterElement));
            ICollection <ElementId> collection = val.ToElementIds();

            foreach (ElementId item2 in collection)
            {
                Element val2 = doc.GetElement(item2);
                for (int i = 0; i < filterNames.Length; i++)
                {
                    if (val2.get_Name() == filterNames[i])
                    {
                        array[i] = true;
                    }
                }
            }
            if (array.Any((bool b) => !b))
            {
                ElementId         val3 = LODapp.GetLODparameter(doc, "Current_LOD").get_Id();
                IList <ElementId> list = (from cat in LODapp.lodCatArray
                                          where (int)cat != -2000220
                                          select new ElementId(cat)).ToList();
                Transaction val4 = new Transaction(doc, "Create LOD filters");
                try
                {
                    val4.Start();
                    for (int j = 0; j < filterNames.Length; j++)
                    {
                        if (!array[j])
                        {
                            ParameterFilterElement val5 = ParameterFilterElement.Create(doc, filterNames[j], (ICollection <ElementId>)list);
                            FilterRule             item = ParameterFilterRuleFactory.CreateEqualsRule(val3, lodValues[j]);
                            val5.SetRules((IList <FilterRule>) new List <FilterRule>(1)
                            {
                                item
                            });
                        }
                    }
                    val4.Commit();
                }
                catch (Exception innerException)
                {
                    val4.RollBack();
                    throw new Exception("Failed to create filters.", innerException);
                }
            }
            return(GetLODfilters(doc));
        }
Esempio n. 3
0
        public static void CreateViewFilter(Document doc, View view)
        {
            List <ElementId> categories = new List <ElementId>();

            categories.Add(new ElementId(BuiltInCategory.OST_Walls));
            List <FilterRule> filterRules = new List <FilterRule>();

            try
            {
                // Create filter element associated to the input categories
                ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, "Example view filter", categories);

                // Criterion 1 - wall type Function is "Exterior"
                ElementId exteriorParamId = new ElementId(BuiltInParameter.FUNCTION_PARAM);
                filterRules.Add(ParameterFilterRuleFactory.CreateEqualsRule(exteriorParamId, (int)WallFunction.Exterior));

                // Criterion 2 - wall height > some number
                ElementId lengthId = new ElementId(BuiltInParameter.CURVE_ELEM_LENGTH);
                filterRules.Add(ParameterFilterRuleFactory.CreateGreaterOrEqualRule(lengthId, 28.0, 0.0001));

                // Criterion 3 - custom shared parameter value matches string pattern
                // Get the id for the shared parameter - the ElementId is not hardcoded, so we need to get an instance of this type to find it
                Guid spGuid = new Guid("96b00b61-7f5a-4f36-a828-5cd07890a02a");
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfClass(typeof(Wall));
                Wall wall = collector.FirstElement() as Wall;

                if (wall != null)
                {
                    Parameter sharedParam   = wall.get_Parameter(spGuid);
                    ElementId sharedParamId = sharedParam.Id;

                    filterRules.Add(ParameterFilterRuleFactory.CreateBeginsWithRule(sharedParamId, "15.", true));
                }

                parameterFilterElement.SetRules(filterRules);

                // Apply filter to view
                view.AddFilter(parameterFilterElement.Id);
                view.SetFilterVisibility(parameterFilterElement.Id, false);
            }
            catch
            {
            }
        }
Esempio n. 4
0
        public static ParameterFilterElement createSimpleFilter(Document doc, List <ElementId> catsIds, string filterName, MyParameter mp, CriteriaType ctype)
        {
            List <ParameterFilterElement> filters = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(ParameterFilterElement))
                                                    .Cast <ParameterFilterElement>()
                                                    .ToList();

            FilterRule rule = null;
            List <ParameterFilterElement> checkFilters = filters.Where(f => f.Name == filterName).ToList();
            ParameterFilterElement        filter       = null;

            if (checkFilters.Count != 0)
            {
                filter = checkFilters[0];
            }
            else
            {
                rule = FilterCreator.CreateRule(mp, ctype);


                if (rule == null)
                {
                    return(null);
                }

                List <FilterRule> filterRules = new List <FilterRule> {
                    rule
                };
                try
                {
                    filter = ParameterFilterElement.Create(doc, filterName, catsIds);
#if R2017 || R2018
                    filter.SetRules(filterRules);
#else
                    filter.SetElementFilter(new ElementParameterFilter(filterRules));
#endif
                }
                catch { }
            }
            return(filter);
        }
Esempio n. 5
0
        public static ParameterFilterElement CreateConstrFilter(Document doc, List <ElementId> catsIds, Parameter markParam, string mark, string filterNamePrefix)
        {
            string filterName = filterNamePrefix + "_Конструкция " + mark;

            ParameterFilterElement filter = DocumentGetter.GetFilterByName(doc, filterName);

            if (filter != null)
            {
                return(filter);
            }

            FilterRule markEquals = ParameterFilterRuleFactory.CreateEqualsRule(markParam.Id, mark, true);

#if R2017 || R2018
            filter = ParameterFilterElement.Create(doc, filterName, catsIds);
            filter.SetRules(new List <FilterRule> {
                markEquals
            });
#else
            ElementParameterFilter epf = new ElementParameterFilter(markEquals);
            filter = ParameterFilterElement.Create(doc, filterName, catsIds, epf);
#endif
            return(filter);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a filter in a Revit Document from a custom FilterST class instance.
        /// </summary>
        /// <param name="doc">The Revit Document Object.</param>
        /// <param name="fRaw">A FilterST object.</param>
        public static void CreateViewFilterFromObject(Document doc, FilterST fRaw)
        {
            string filterName = fRaw.Name;
            ICollection <ElementId> categories  = fRaw.Categories;
            List <FilterRule>       filterRules = fRaw.FilterRules;

            try
            {
                using (Transaction t = new Transaction(doc, "Add View Filter"))
                {
                    t.Start();

                    ParameterFilterElement parameterFilterElement = ParameterFilterElement.Create(doc, filterName, categories);
                    parameterFilterElement.SetRules(filterRules);

                    t.Commit();
                    t.Dispose();
                }
            }
            catch (Exception filterException)
            {
                MessageBox.Show(filterException.Message);
            }
        }
Esempio n. 7
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            AppBatchFilterCreation.assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string dllPath = Path.GetDirectoryName(AppBatchFilterCreation.assemblyPath);

            OpenFileDialog openCsvDialog = new OpenFileDialog();

            openCsvDialog.Filter           = "CSV file|*.csv";
            openCsvDialog.Title            = "Выберите файл CSV (v2018.10.17)";
            openCsvDialog.Multiselect      = false;
            openCsvDialog.InitialDirectory = dllPath;

            if (openCsvDialog.ShowDialog() != DialogResult.OK)
            {
                return(Result.Cancelled);
            }
            ;

            //считываю файл
            string          path = openCsvDialog.FileName;
            List <string[]> data = ReadDataFromCSV.Read(path);

            string msg         = "";
            int    filterCount = 0;

            //одна строка в файле - один фильтр
            foreach (string[] line in data)
            {
                FilterSourceInfo filterSource = new FilterSourceInfo(line);
                string           filterName   = filterSource.FilterName;

                //Добавляю категории
                List <ElementId> catIds = new List <ElementId>();
                foreach (string stringCat in filterSource.Categories)
                {
                    BuiltInCategory cat = GetBuiltinCategory.GetCategoryByRussianName(stringCat);
                    catIds.Add(new ElementId(cat));
                }


                //добавляю критерии фильтрации
                List <FilterRule> filterRules = new List <FilterRule>();

                foreach (string[] sourceRule in filterSource.SourceRules)
                {
                    string paramName = sourceRule[0];
                    string function  = sourceRule[1];
                    string value     = sourceRule[2];


                    BuiltInCategory cat = GetBuiltinCategory.GetCategoryByRussianName(filterSource.Categories[0]);
                    if (cat == BuiltInCategory.OST_Sections || cat == BuiltInCategory.OST_Elev || cat == BuiltInCategory.OST_Callouts)
                    {
                        cat = BuiltInCategory.OST_Views;
                    }

                    FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(cat);

                    Parameter param = null;
                    try
                    {
                        foreach (Element elem in collector)
                        {
                            param = elem.LookupParameter(paramName);
                            if (param == null)
                            {
                                continue;
                            }
                            break;
                        }
                    }
                    catch { }

                    if (collector.Count() == 0 || param == null)
                    {
                        message  = "Ошибка при создании фильтра: " + filterName;
                        message += "\nУстановите как минимум один элемент в категории: " + filterSource.Categories[0];
                        message += "\nТребуемый параметр: " + paramName;
                        return(Result.Failed);
                    }

                    FilterRule rule = FilterCreator.CreateRule2(param, function, value);
                    filterRules.Add(rule);
                }

                try
                {
                    using (Transaction t = new Transaction(doc))
                    {
                        t.Start("Создание фильтра" + filterName);
                        ParameterFilterElement filter = ParameterFilterElement.Create(doc, filterName, catIds);
#if R2017 || R2018
                        filter.SetRules(filterRules);
#else
                        ElementParameterFilter epf = new ElementParameterFilter(filterRules);
                        filter.SetElementFilter(epf);
#endif
                        filterCount++;
                        t.Commit();
                    }
                }
                catch
                {
                    msg += filterName + "\n";
                }
            }
            string finalMessage = "Создано фильтров: " + filterCount.ToString() + "\n";
            if (msg.Length != 0)
            {
                finalMessage += "Не удалось создать: \n" + msg;
            }

            TaskDialog.Show("Batch filter create", finalMessage);
            return(Result.Succeeded);
        }
Esempio n. 8
0
        public static ParameterFilterElement CreateRebarHostFilter(
            Document doc, List <ElementId> rebarCatsIds, Parameter rebarIsFamilyParam, Parameter rebarHostParam, Parameter rebarMrkParam,
            string hostMark, string filterNamePrefix, RebarFilterMode filterMode)
        {
            string filterName = filterNamePrefix + "_Арм Конструкции " + hostMark;

            if (filterMode == RebarFilterMode.IfcMode)
            {
                filterName += " IFC";
            }
            ParameterFilterElement filter = DocumentGetter.GetFilterByName(doc, filterName);

            if (filter != null)
            {
                return(filter);
            }

            FilterRule ruleHostEquals = ParameterFilterRuleFactory.CreateEqualsRule(rebarHostParam.Id, hostMark, true);

            if (filterMode == RebarFilterMode.SingleMode)
            {
#if R2017 || R2018
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleHostEquals
                });
#else
                ElementParameterFilter epf = new ElementParameterFilter(ruleHostEquals);
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds, epf);
#endif
                return(filter);
            }

            FilterRule ruleIsNotFamily = ParameterFilterRuleFactory.CreateEqualsRule(rebarIsFamilyParam.Id, 0);
            FilterRule ruleIsFamily    = ParameterFilterRuleFactory.CreateEqualsRule(rebarIsFamilyParam.Id, 1);
            FilterRule ruleMrkEquals   = ParameterFilterRuleFactory.CreateEqualsRule(rebarMrkParam.Id, hostMark, true);


#if R2017 || R2018
            if (filterMode == RebarFilterMode.StandardRebarMode)
            {
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleIsNotFamily, ruleHostEquals
                });
                return(filter);
            }
            else if (filterMode == RebarFilterMode.IfcMode)
            {
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds);
                filter.SetRules(new List <FilterRule> {
                    ruleIsFamily, ruleMrkEquals
                });
                return(filter);
            }
#else
            if (filterMode == RebarFilterMode.DoubleMode)
            {
                ElementParameterFilter filterByStandardArm = new ElementParameterFilter(new List <FilterRule> {
                    ruleIsNotFamily, ruleHostEquals
                });
                ElementParameterFilter filterForIfcArm = new ElementParameterFilter(new List <FilterRule> {
                    ruleIsFamily, ruleMrkEquals
                });
                LogicalOrFilter orfilter = new LogicalOrFilter(filterByStandardArm, filterForIfcArm);
                filter = ParameterFilterElement.Create(doc, filterName, rebarCatsIds, orfilter);
                return(filter);
            }
#endif
            return(null);
        }