/// <summary> /// Returns all the used filters in a project /// </summary> /// <param name="doc"></param> /// <returns></returns> private void GetUsedFilters() { FilteredElementCollector collector = new FilteredElementCollector(doc); IList <Element> views = collector.OfClass(typeof(Autodesk.Revit.DB.View)).ToElements(); foreach (Element el in views) { Autodesk.Revit.DB.View v = el as Autodesk.Revit.DB.View; ICollection <ElementId> filterIds; try { filterIds = v.GetFilters(); } catch (AmbiguousMatchException) { continue; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { continue; } foreach (ElementId id in filterIds) { OverrideGraphicSettings filterOverrides = v.GetFilterOverrides(id); bool filterVisible = v.GetFilterVisibility(id); if (CompareOverrides(filterOverrides, _defaultOverrides) && filterVisible) { if (removeFromView) { using (Transaction t = new Transaction(doc, "Remove filter")) { t.Start(); v.RemoveFilter(id); t.Commit(); } removed++; continue; } else { unused.Add(id); } } used.Add(id); } } if (removeFromView) { TaskDialog.Show("Unused on Views Filters", "Unused filters on views" + Environment.NewLine + removed.ToString() + " filters removed."); } }
public static void RemoveFilterFromView(Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement) { Transaction t = new Transaction(doc); bool filterExistsInActiveView = view.GetFilters().Any(id => doc.GetElement(id).Name.Equals("Voiles Porteurs")); if (filterExistsInActiveView) { t.Start("Remove filter from active view"); view.RemoveFilter(filterElement.Id); t.Commit(); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication _uiapp = commandData.Application; UIDocument _uidoc = _uiapp.ActiveUIDocument; Document _doc = _uidoc.Document; Autodesk.Revit.DB.View activeV = _doc.ActiveView; SelectionFilterElement filterElement = new FilteredElementCollector(_doc) .OfClass(typeof(SelectionFilterElement)).Cast <SelectionFilterElement>() .Where(sf => sf.Name.Equals("Voiles Porteurs")) .FirstOrDefault(); using (Transaction t = new Transaction(_doc, "Remove walls from filter")) { t.Start(); bool filterExistsInActiveView = false; if (activeV.GetFilters().Count != 0) { foreach (ElementId id in activeV.GetFilters()) { if (_doc.GetElement(id).Name.Equals("Voiles Porteurs")) { filterExistsInActiveView = true; } } } if (!filterExistsInActiveView) { MessageBox.Show("No filter is added to the active view!"); return(Result.Cancelled); } else { IList <Reference> refIds; try { refIds = _uidoc.Selection.PickObjects(ObjectType.Element, new WallSelectionFilter(activeV.GenLevel.Id, filterElement)); } catch (OperationCanceledException) { return(Result.Cancelled); } catch (Exception) { return(Result.Failed); } foreach (Reference refe in refIds) { filterElement.RemoveSingle(refe.ElementId); } activeV.RemoveFilter(filterElement.Id); ViewTemplate.AddFilterToView( _doc, activeV, filterElement, new Color(000, 128, 255), new string[] { "Uni", "Solid fill" }, new Color(000, 128, 255), new string[] { "Uni", "Solid fill" }); } t.Commit(); } _uidoc.RefreshActiveView(); return(Result.Succeeded); }
/// <summary> /// Returns all the used filters in a project /// </summary> /// <param name="doc"></param> /// <returns></returns> private void GetUsedFilters() { //FilteredElementCollector collector = new FilteredElementCollector(doc); //IList<Element> views = collector.OfClass(typeof(Autodesk.Revit.DB.View)).WhereElementIsNotElementType().ToElements(); //Filted Out the Sheets FilteredElementCollector collViewPlan = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)).WhereElementIsNotElementType(); FilteredElementCollector collViewSection = new FilteredElementCollector(doc).OfClass(typeof(ViewSection)).WhereElementIsNotElementType(); FilteredElementCollector collView3D = new FilteredElementCollector(doc).OfClass(typeof(View3D)).WhereElementIsNotElementType(); IList <Element> filteredViews = new List <Element>(); foreach (var item in collViewPlan) { filteredViews.Add(item); } foreach (var item in collViewSection) { filteredViews.Add(item); } foreach (var item in collView3D) { filteredViews.Add(item); } foreach (Element el in filteredViews) { Autodesk.Revit.DB.View v = el as Autodesk.Revit.DB.View; ICollection <ElementId> filterIds; try { filterIds = v.GetFilters(); } catch (AmbiguousMatchException) { continue; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { continue; } foreach (ElementId id in filterIds) { if (used.Contains(id)) { continue; } OverrideGraphicSettings filterOverrides = v.GetFilterOverrides(id); bool filterVisible = v.GetFilterVisibility(id); if (CompareOverrides(filterOverrides, _defaultOverrides) && filterVisible) { unassigned.Add(id); } else { used.Add(id); } } } unassigned = new HashSet <ElementId>(unassigned.ToList().Except(used.ToList())); }
private Autodesk.Revit.DB.View CreateTemplateFor3DView(Autodesk.Revit.DB.View viewTemplate) { Transaction t = new Transaction(_doc); t.Start("Create view template 'DCE Structure 3D'"); // Copy an existing view template ICollection <ElementId> copyIds = new Collection <ElementId> { viewTemplate.Id }; // Create a default CopyPasteOptions CopyPasteOptions cpOpts = new CopyPasteOptions(); ElementId tmpId = ElementTransformUtils.CopyElements( _doc, copyIds, _doc, Transform.Identity, cpOpts) .First(); viewTemplate = _doc.GetElement(tmpId) as Autodesk.Revit.DB.View; viewTemplate.Name = THREED_VIEW_TEMPLATE_NAME; t.Commit(); // Ensure that the parameters are included in "DCE Structure 3D" view template List <BuiltInParameter> bipList = new List <BuiltInParameter>() { BuiltInParameter.VIEW_SCALE_PULLDOWN_METRIC, BuiltInParameter.VIEW_DETAIL_LEVEL, // BuiltInParameter.VIEW_PARTS_VISIBILITY, BuiltInParameter.VIS_GRAPHICS_MODEL, BuiltInParameter.VIS_GRAPHICS_ANNOTATION, // BuiltInParameter.VIS_GRAPHICS_ANALYTICAL_MODEL, // BuiltInParameter.VIS_GRAPHICS_IMPORT, BuiltInParameter.VIS_GRAPHICS_FILTERS, BuiltInParameter.VIS_GRAPHICS_RVT_LINKS, BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_MODEL, //BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_SHADOWS, //BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_SKETCHY_LINES, //BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_LIGHTING, //BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_PHOTO_EXPOSURE, //BuiltInParameter.GRAPHIC_DISPLAY_OPTIONS_BACKGROUND, //BuiltInParameter.VIEW_PHASE_FILTER, BuiltInParameter.VIEW_DISCIPLINE, BuiltInParameter.VIEW_SHOW_HIDDEN_LINES, //BuiltInParameter.VIEWER3D_RENDER_SETTINGS }; ViewTemplate.IncludParamToViewTemplate(_doc, viewTemplate, bipList); List <BuiltInCategory> bicList = new List <BuiltInCategory> { BuiltInCategory.OST_Walls, BuiltInCategory.OST_StructuralColumns, BuiltInCategory.OST_StructuralFraming, BuiltInCategory.OST_Floors, BuiltInCategory.OST_StructuralFoundation }; ViewTemplate.SetOnlyCategoriesVisible(_doc, viewTemplate, bicList); t.Start("Set view display paramters"); // Set the scale value viewTemplate.Scale = 400; // Set the detail level viewTemplate.DetailLevel = ViewDetailLevel.Fine; // Set the display style viewTemplate.DisplayStyle = DisplayStyle.ShadingWithEdges; // Set the discipline viewTemplate.Discipline = ViewDiscipline.Structural; OverrideGraphicSettings ogs = new OverrideGraphicSettings(); ogs.SetSurfaceTransparency(50); ogs.SetCutFillPatternVisible(false); viewTemplate.SetCategoryOverrides( _doc.Settings.Categories.get_Item(BuiltInCategory.OST_Floors).Id, ogs); // Remove all the filter in the view template foreach (ElementId id in viewTemplate.GetFilters()) { viewTemplate.RemoveFilter(id); } t.Commit(); return(viewTemplate); }