Beispiel #1
0
        public SelectionFilterElement LoadFilter(UIDocument uidoc)
        {
            FilteredElementCollector collector      = new FilteredElementCollector(uidoc.Document);
            ICollection <Element>    typecollection = collector.OfClass(typeof(SelectionFilterElement)).ToElements();

            SelectionFilterElement sef = typecollection.Cast <SelectionFilterElement>().FirstOrDefault(ele => ele.Name == FilterName);

            if (sef != null)
            {
                uidoc.Selection.GetElementIds().Clear();
                uidoc.Selection.SetElementIds(sef.GetElementIds());
            }

            return(sef);
        }
Beispiel #2
0
        public static IEnumerable <ElementId> ElementIdsBySelectionSet(this Document document, string selectionSetName, bool caseSensitive, IEnumerable <ElementId> ids = null)
        {
            if (document == null)
            {
                return(null);
            }

            if (ids != null && ids.Count() == 0)
            {
                return(new List <ElementId>());
            }

            List <SelectionFilterElement> selectionFilterElements = new FilteredElementCollector(document).OfClass(typeof(SelectionFilterElement)).Cast <SelectionFilterElement>().ToList();

            SelectionFilterElement selectionFilterElement = null;

            if (caseSensitive)
            {
                selectionFilterElement = selectionFilterElements.Find(x => x.Name == selectionSetName);
            }
            else
            {
                selectionFilterElement = selectionFilterElements.Find(x => !string.IsNullOrEmpty(x.Name) && x.Name.ToUpper() == selectionSetName.ToUpper());
            }

            if (selectionFilterElement == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Couldn't find a Selection Set named " + selectionSetName + ".");
                return(new HashSet <ElementId>());
            }

            HashSet <ElementId> result = new HashSet <ElementId>(selectionFilterElement.GetElementIds());

            if (ids != null)
            {
                result.IntersectWith(ids);
            }

            return(result);
        }
Beispiel #3
0
        public SelectionFilterElement LoadFilter(UIDocument uidoc)
        {
            Document doc = uidoc.Document;
            FilteredElementCollector collector      = new FilteredElementCollector(uidoc.Document);
            ICollection <Element>    typecollection = collector.OfClass(typeof(SelectionFilterElement)).ToElements();

            SelectionFilterElement sef = typecollection.Cast <SelectionFilterElement>().FirstOrDefault(ele => ele.Name == FilterName);

            if (sef != null)
            {
                var elements = uidoc.Selection.GetElementIds()
                               .ToList()
                               .Select(id => doc.GetElement(id))
                               .ToList();
                elements.Clear();
                foreach (ElementId id in sef.GetElementIds())
                {
                    elements.Add(uidoc.Document.GetElement(id));
                }
            }

            return(sef);
        }
 public static IEnumerable <ElementId> ElementIdsOfMemberElements(this SelectionFilterElement selectionSet)
 {
     return(selectionSet.GetElementIds());
 }