示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        private void UpdatePluntSystem(List <FamilyInstance> allPlunts, ref List <FamilyInstance> failedPlunts)
        {
            UI.ProgressBar pBar = new UI.ProgressBar("Назначение систем", allPlunts.Count);
            foreach (FamilyInstance plunt in allPlunts)
            {
                Space  space      = GetSpaceOfPlant(plunt);
                string systemName = null;
                if (space != null)
                {
                    string systemTypeName  = plunt.get_Parameter(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM).AsValueString();
                    string systemClassName = plunt.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsString();
                    if (systemTypeName == suplySystemTypeName)
                    {
                        systemName = space.LookupParameter(supplySystemParameterName).AsString();
                    }
                    else if (systemTypeName == exhaustSystemTypeName)
                    {
                        systemName = space.LookupParameter(exhaustSystemParameterName).AsString();
                    }

                    /*else if (systemTypeName == "Не определено")
                     * {
                     *  if (systemClassName == "Приточный воздух") systemName = space.LookupParameter(supplySystemParameterName).AsString();
                     *  else if (systemClassName == "Отработанный воздух") systemName = space.LookupParameter(exhaustSystemParameterName).AsString();
                     * }*/
                    if (systemName != null)
                    {
                        ConnectorSet connectors    = plunt.MEPModel.ConnectorManager.Connectors;
                        Connector    baseConnector = connectors.Cast <Connector>().FirstOrDefault();
                        MEPSystem    fromSystem    = baseConnector?.MEPSystem;
                        MEPSystem    toSystem      = new FilteredElementCollector(doc).OfClass(typeof(MEPSystem)).Cast <MEPSystem>().Where(x => x.Name == systemName).FirstOrDefault();
                        if (fromSystem?.Id.IntegerValue == toSystem?.Id.IntegerValue)
                        {
                            continue;
                        }
                        if (fromSystem == null && toSystem == null)
                        {
                            DuctSystemType ductType = DuctSystemType.UndefinedSystemType;
                            if (systemTypeName == suplySystemTypeName)
                            {
                                ductType = DuctSystemType.SupplyAir;
                            }
                            else if (systemTypeName == exhaustSystemTypeName)
                            {
                                ductType = DuctSystemType.ExhaustAir;
                            }
                            toSystem      = doc.Create.NewMechanicalSystem(null, connectors, ductType);
                            toSystem.Name = systemName;
                        }
                        else if (fromSystem == null && toSystem != null)
                        {
                            toSystem.Add(connectors);
                        }
                        else if (fromSystem != null && toSystem == null)
                        {
                            fromSystem.Name = systemName;
                        }
                        else if (fromSystem != null && toSystem != null)
                        {
                            try
                            {
                                if (fromSystem.ConnectorManager.Connectors.Size > 1)
                                {
                                    ConnectorSet smallSet = new ConnectorSet();
                                    smallSet.Insert(baseConnector);
                                    fromSystem.Remove(smallSet);
                                    toSystem.Add(smallSet);
                                }
                                else
                                {
                                    failedPlunts.Add(plunt);
                                }
                            }
                            catch (Autodesk.Revit.Exceptions.ArgumentException)
                            {
                                failedPlunts.Add(plunt);
                            }
                            finally { pBar.StepUp(); }
                        }
                    }
                    else
                    {
                        failedPlunts.Add(plunt);
                    }
                }
                pBar.StepUp();
            }
        }