public override List <ISelectionFilter> GetSelectionFilters()
        {
            var categories = new List <string>();
            var parameters = new List <string>();
            var views      = new List <string>();

            if (CurrentDoc != null)
            {
                //selectionCount = CurrentDoc.Selection.GetElementIds().Count();
                categories = ConnectorRevitUtils.GetCategoryNames(CurrentDoc.Document);
                parameters = ConnectorRevitUtils.GetParameterNames(CurrentDoc.Document);
                views      = ConnectorRevitUtils.GetViewNames(CurrentDoc.Document);
            }

            return(new List <ISelectionFilter>
            {
                new ListSelectionFilter {
                    Name = "Category", Icon = "Category", Values = categories
                },
                new ListSelectionFilter {
                    Name = "View", Icon = "RemoveRedEye", Values = views
                },
                new PropertySelectionFilter
                {
                    Name = "Parameter",
                    Icon = "FilterList",
                    HasCustomProperty = false,
                    Values = parameters,
                    Operators = new List <string> {
                        "equals", "contains", "is greater than", "is less than"
                    }
                }
            });
        }
Esempio n. 2
0
        //TODO: store these string values in something more solid to avoid typos?
        public override List <ISelectionFilter> GetSelectionFilters()
        {
            var categories  = new List <string>();
            var parameters  = new List <string>();
            var views       = new List <string>();
            var projectInfo = new List <string> {
                "Project Info", "Levels", "Views 2D", "Views 3D", "Families & Types"
            };

            if (CurrentDoc != null)
            {
                //selectionCount = CurrentDoc.Selection.GetElementIds().Count();
                categories = ConnectorRevitUtils.GetCategoryNames(CurrentDoc.Document);
                parameters = ConnectorRevitUtils.GetParameterNames(CurrentDoc.Document);
                views      = ConnectorRevitUtils.GetViewNames(CurrentDoc.Document);
            }

            return(new List <ISelectionFilter>
            {
                new ListSelectionFilter {
                    Slug = "category", Name = "Cat", Icon = "Category", Values = categories, Description = "Adds all objects belonging to the selected categories"
                },
                new ListSelectionFilter {
                    Slug = "view", Name = "View", Icon = "RemoveRedEye", Values = views, Description = "Adds all objects visible in the selected views"
                },
                new ListSelectionFilter {
                    Slug = "project-info", Name = "P. Info", Icon = "Information", Values = projectInfo, Description = "Adds the selected project information such as levels, views and family names to the stream"
                },
                new PropertySelectionFilter
                {
                    Slug = "param",
                    Name = "Param",
                    Description = "Adds  all objects satisfying the selected parameter",
                    Icon = "FilterList",
                    HasCustomProperty = false,
                    Values = parameters,
                    Operators = new List <string> {
                        "equals", "contains", "is greater than", "is less than"
                    }
                },
                new AllSelectionFilter {
                    Slug = "all", Name = "All", Icon = "CubeScan", Description = "Selects all document objects and project information."
                }
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Given the filter in use by a stream returns the document elements that match it.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private List <Element> GetSelectionFilterObjects(ISelectionFilter filter)
        {
            var doc = CurrentDoc.Document;

            var selection = new List <Element>();

            switch (filter.Name)
            {
            case "Category":
                var catFilter  = filter as ListSelectionFilter;
                var bics       = new List <BuiltInCategory>();
                var categories = ConnectorRevitUtils.GetCategories(doc);
                IList <ElementFilter> elementFilters = new List <ElementFilter>();

                foreach (var cat in catFilter.Selection)
                {
                    elementFilters.Add(new ElementCategoryFilter(categories[cat].Id));
                }

                var categoryFilter = new LogicalOrFilter(elementFilters);

                selection = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(categoryFilter).ToList();
                return(selection);

            case "View":
                var viewFilter = filter as ListSelectionFilter;

                var views = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .OfClass(typeof(View))
                            .Where(x => viewFilter.Selection.Contains(x.Name));

                foreach (var view in views)
                {
                    var ids = selection.Select(x => x.UniqueId);

                    var viewElements = new FilteredElementCollector(doc, view.Id)
                                       .WhereElementIsNotElementType()
                                       .WhereElementIsViewIndependent()
                                       .Where(x => x.IsPhysicalElement())
                                       .Where(x => !ids.Contains(x.UniqueId)) //exclude elements already added from other views
                                       .ToList();

                    selection.AddRange(viewElements);
                }
                return(selection);

            case "Project Info":
                var projectInfoFilter = filter as ListSelectionFilter;

                if (projectInfoFilter.Selection.Contains("Project Info"))
                {
                    selection.Add(doc.ProjectInformation);
                }

                if (projectInfoFilter.Selection.Contains("Views 2D"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Views)
                                       .Cast <View>()
                                       .Where(x => x.ViewType == ViewType.CeilingPlan ||
                                              x.ViewType == ViewType.FloorPlan ||
                                              x.ViewType == ViewType.Elevation ||
                                              x.ViewType == ViewType.Section)
                                       .ToList());
                }

                if (projectInfoFilter.Selection.Contains("Views 3D"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Views)
                                       .Cast <View>()
                                       .Where(x => x.ViewType == ViewType.ThreeD)
                                       .ToList());
                }

                if (projectInfoFilter.Selection.Contains("Levels"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Levels).ToList());
                }

                if (projectInfoFilter.Selection.Contains("Families & Types"))
                {
                    //get all the elementtypes of the categories we support
                    var allCategoryFilter = new LogicalOrFilter(ConnectorRevitUtils.GetCategories(doc).Select(x => new ElementCategoryFilter(x.Value.Id)).Cast <ElementFilter>().ToList());

                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsElementType()
                                       .WherePasses(allCategoryFilter).ToList());
                }
                return(selection);

            case "Parameter":
                try
                {
                    var propFilter = filter as PropertySelectionFilter;
                    var query      = new FilteredElementCollector(doc)
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsViewIndependent()
                                     .Where(x => x.IsPhysicalElement())
                                     .Where(fi => fi.LookupParameter(propFilter.PropertyName) != null);

                    propFilter.PropertyValue = propFilter.PropertyValue.ToLowerInvariant();

                    switch (propFilter.PropertyOperator)
                    {
                    case "equals":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)) == propFilter.PropertyValue);
                        break;

                    case "contains":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)).Contains(propFilter.PropertyValue));
                        break;

                    case "is greater than":
                        query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) >
                                            double.Parse(propFilter.PropertyValue));
                        break;

                    case "is less than":
                        query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) <
                                            double.Parse(propFilter.PropertyValue));
                        break;
                    }

                    selection = query.ToList();
                }
                catch (Exception e)
                {
                    Log.CaptureException(e);
                }
                return(selection);
            }

            return(selection);
        }
Esempio n. 4
0
        /// <summary>
        /// Given the filter in use by a stream returns the document elements that match it.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private List <Element> GetSelectionFilterObjects(ISelectionFilter filter)
        {
            var doc = CurrentDoc.Document;

            var selection = new List <Element>();

            switch (filter.Slug)
            {
            case "all":
                selection.AddRange(doc.SupportedElements()); // includes levels
                selection.Add(doc.ProjectInformation);
                selection.AddRange(doc.Views2D());
                selection.AddRange(doc.Views3D());
                selection.AddRange(doc.SupportedTypes());
                return(selection);

            case "category":
                var catFilter  = filter as ListSelectionFilter;
                var bics       = new List <BuiltInCategory>();
                var categories = ConnectorRevitUtils.GetCategories(doc);
                IList <ElementFilter> elementFilters = new List <ElementFilter>();

                foreach (var cat in catFilter.Selection)
                {
                    elementFilters.Add(new ElementCategoryFilter(categories[cat].Id));
                }

                var categoryFilter = new LogicalOrFilter(elementFilters);

                selection = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(categoryFilter).ToList();
                return(selection);

            case "view":
                var viewFilter = filter as ListSelectionFilter;

                var views = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .OfClass(typeof(View))
                            .Where(x => viewFilter.Selection.Contains(x.Name));

                foreach (var view in views)
                {
                    var ids = selection.Select(x => x.UniqueId);

                    var viewElements = new FilteredElementCollector(doc, view.Id)
                                       .WhereElementIsNotElementType()
                                       .WhereElementIsViewIndependent()
                                       .Where(x => x.IsPhysicalElement())
                                       .Where(x => !ids.Contains(x.UniqueId)) //exclude elements already added from other views
                                       .ToList();

                    selection.AddRange(viewElements);
                }
                return(selection);

            case "project-info":
                var projectInfoFilter = filter as ListSelectionFilter;

                if (projectInfoFilter.Selection.Contains("Project Info"))
                {
                    selection.Add(doc.ProjectInformation);
                }

                if (projectInfoFilter.Selection.Contains("Views 2D"))
                {
                    selection.AddRange(doc.Views2D());
                }

                if (projectInfoFilter.Selection.Contains("Views 3D"))
                {
                    selection.AddRange(doc.Views3D());
                }

                if (projectInfoFilter.Selection.Contains("Levels"))
                {
                    selection.AddRange(doc.Levels());
                }

                if (projectInfoFilter.Selection.Contains("Families & Types"))
                {
                    selection.AddRange(doc.SupportedTypes());
                }

                return(selection);

            case "param":
                try
                {
                    var propFilter = filter as PropertySelectionFilter;
                    var query      = new FilteredElementCollector(doc)
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsViewIndependent()
                                     .Where(x => x.IsPhysicalElement())
                                     .Where(fi => fi.LookupParameter(propFilter.PropertyName) != null);

                    propFilter.PropertyValue = propFilter.PropertyValue.ToLowerInvariant();

                    switch (propFilter.PropertyOperator)
                    {
                    case "equals":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)) == propFilter.PropertyValue);
                        break;

                    case "contains":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)).Contains(propFilter.PropertyValue));
                        break;

                    case "is greater than":
                        query = query.Where(fi => RevitVersionHelper.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName)) >
                                            double.Parse(propFilter.PropertyValue));
                        break;

                    case "is less than":
                        query = query.Where(fi => RevitVersionHelper.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName)) <
                                            double.Parse(propFilter.PropertyValue));
                        break;
                    }

                    selection = query.ToList();
                }
                catch (Exception e)
                {
                    Log.CaptureException(e);
                }
                return(selection);
            }

            return(selection);
        }
    /// <summary>
    /// Given the filter in use by a stream returns the document elements that match it.
    /// </summary>
    /// <param name="filter"></param>
    /// <returns></returns>
    private List<Base> GetSelectionFilterObjects(ISelectionFilter filter)
    {
      var doc = CurrentDoc.Document;

      var selectionIds = new List<string>();

      switch (filter.Name)
      {
        case "Category":
          var catFilter = filter as ListSelectionFilter;
          var bics = new List<BuiltInCategory>();
          var categories = ConnectorRevitUtils.GetCategories(doc);
          IList<ElementFilter> elementFilters = new List<ElementFilter>();

          foreach (var cat in catFilter.Selection)
          {
            elementFilters.Add(new ElementCategoryFilter(categories[cat].Id));
          }

          var categoryFilter = new LogicalOrFilter(elementFilters);

          selectionIds = new FilteredElementCollector(doc)
            .WhereElementIsNotElementType()
            .WhereElementIsViewIndependent()
            .WherePasses(categoryFilter)
            .Select(x => x.UniqueId).ToList();
          break;

        case "View":
          var viewFilter = filter as ListSelectionFilter;

          var views = new FilteredElementCollector(doc)
            .WhereElementIsNotElementType()
            .OfClass(typeof(View))
            .Where(x => viewFilter.Selection.Contains(x.Name));

          foreach (var view in views)
          {
            var ids = new FilteredElementCollector(doc, view.Id)
              .WhereElementIsNotElementType()
              .WhereElementIsViewIndependent()
              .Where(x => x.IsPhysicalElement())
              .Select(x => x.UniqueId).ToList();

            selectionIds = selectionIds.Union(ids).ToList();
          }
          break;

        case "Parameter":
          try
          {
            var propFilter = filter as PropertySelectionFilter;
            var query = new FilteredElementCollector(doc)
              .WhereElementIsNotElementType()
              .WhereElementIsNotElementType()
              .WhereElementIsViewIndependent()
              .Where(x => x.IsPhysicalElement())
              .Where(fi => fi.LookupParameter(propFilter.PropertyName) != null);

            propFilter.PropertyValue = propFilter.PropertyValue.ToLowerInvariant();

            switch (propFilter.PropertyOperator)
            {
              case "equals":
                query = query.Where(fi =>
                  GetStringValue(fi.LookupParameter(propFilter.PropertyName)) == propFilter.PropertyValue);
                break;
              case "contains":
                query = query.Where(fi =>
                  GetStringValue(fi.LookupParameter(propFilter.PropertyName)).Contains(propFilter.PropertyValue));
                break;
              case "is greater than":
                query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                            fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                            fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) >
                                          double.Parse(propFilter.PropertyValue));
                break;
              case "is less than":
                query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                            fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                            fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) <
                                          double.Parse(propFilter.PropertyValue));
                break;
            }

            selectionIds = query.Select(x => x.UniqueId).ToList();
          }
          catch (Exception e)
          {
            Log.CaptureException(e);
          }
          break;
      }

      return selectionIds.Select(id => new Base { applicationId = id }).ToList();
    }