예제 #1
0
        public static void AddFilterToView(
            Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement,
            Color cutFillColor, string[] cutFillPatterns, Color projFillColor, string[] projFillPatterns)
        {
            using (Transaction t = new Transaction(doc, "Add filter to view and set overrides"))
            {
                t.Start();
                ElementId filterId = filterElement.Id;
                view.AddFilter(filterId);

                doc.Regenerate();

                OverrideGraphicSettings overrideSettings = view.GetFilterOverrides(filterId);
                Element cutFill = (from element in new FilteredElementCollector(doc)
                                   .OfClass(typeof(FillPatternElement)).Cast <Element>()
                                   where cutFillPatterns.Any(pattern => pattern.Equals(element.Name))
                                   select element)
                                  .FirstOrDefault();
                Element projectFill = (from element in new FilteredElementCollector(doc)
                                       .OfClass(typeof(FillPatternElement)).Cast <Element>()
                                       where projFillPatterns.Any(pattern => pattern.Equals(element.Name))
                                       select element)
                                      .FirstOrDefault();

                overrideSettings.SetCutFillColor(cutFillColor);
                overrideSettings.SetCutFillPatternId(cutFill.Id);
                overrideSettings.SetProjectionFillColor(projFillColor);
                overrideSettings.SetProjectionFillPatternId(projectFill.Id);
                view.SetFilterOverrides(filterId, overrideSettings);
                t.Commit();
            }
        }
예제 #2
0
        /// <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.");
            }
        }
예제 #3
0
        /// <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()));
        }
예제 #4
0
        private void BtnTransfer_Click(object sender, EventArgs e)
        {
            List <string> infoFiltersTransferred      = new List <string>();
            List <string> infoFiltersGraphicOverriden = new List <string>();

            #region items selected?
            if (LsvFilters.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more View Filters from the list to continue.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
                return;
            }
            if (LsvTemplates.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Select";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more View Templates from the list to continue.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); }
                return;
            }
            #endregion

            #region CHECK IF FILTER IS ALREADY APPLIED
            List <string> infoIsFilterApplied    = new List <string>();
            bool          triggerIsFilterApplied = false;
            foreach (ListViewItem tItem in LsvTemplates.CheckedItems)    // LOOP THROUGH TEMPLATES
            {
                ElementId templateId            = new ElementId(tItem.ImageIndex);
                Autodesk.Revit.DB.View template = m_doc.GetElement(templateId) as Autodesk.Revit.DB.View;

                foreach (ListViewItem vItem in LsvFilters.CheckedItems)  // LOOP THROUGH FILTERS
                {
                    ElementId filterId = new ElementId(vItem.ImageIndex);
                    if (template.IsFilterApplied(filterId))
                    {
                        infoIsFilterApplied.Add(string.Format("{0} -> {1}", vItem.Text, template.Name));
                        triggerIsFilterApplied = true;
                    }
                }
            }
            if (triggerIsFilterApplied)
            {
                // show warning form
                UI.Info.Form_Warning.warningHead = "You should know...";
                UI.Info.Form_Warning.warningMain = "The following Filters are already applied to one or more selected View Templates:";
                UI.Info.Form_Warning.warningFoot = "Graphic settings will be overriden.";
                UI.Info.Form_Warning.warningList = infoIsFilterApplied;
                using (UI.Info.Form_Warning thisForm = new Info.Form_Warning())
                {
                    thisForm.ShowDialog();
                }
            }
            #endregion

            #region PROCEED WITH TRANSACTION
            executionTime.Start();
            using (Transaction t = new Transaction(m_doc, "Transfer View Filters"))
            {
                Ana_NoOfTemplates = LsvTemplates.CheckedItems.Count;     // collect data for analytics

                t.Start();
                // FOR EACH FILTER SELECTED FROM THE LIST, GET HOST VIEW TEMPLATE AND GRAPHIC OVERRIDES
                foreach (ListViewItem filterItem in LsvFilters.CheckedItems)
                {
                    ElementId filterId = new ElementId(filterItem.ImageIndex);
                    // GET SOURCE VIEW TEMPLATE TO GET GRAPHIC OVERRIDES
                    Autodesk.Revit.DB.View  sourceTemplate = Data.Helpers.GetTemplateByName(m_doc, filterItem.Group.ToString());
                    OverrideGraphicSettings graphSetting   = sourceTemplate.GetFilterOverrides(filterId);

                    //FOR EACH TARGET TEMPLATE SELECTED, APPLY FILTERS
                    foreach (ListViewItem templateItem in LsvTemplates.CheckedItems)
                    {
                        ElementId templateId = new ElementId(templateItem.ImageIndex);
                        Autodesk.Revit.DB.View targetTemplate = m_doc.GetElement(templateId) as Autodesk.Revit.DB.View;

                        if (!targetTemplate.IsFilterApplied(filterId))   // IF FILTER IS NOT APPLIED, ADD FILTER AND OVERRIDE GRAPHICS
                        {
                            targetTemplate.AddFilter(filterId);
                            targetTemplate.SetFilterOverrides(filterId, graphSetting);

                            infoFiltersTransferred.Add(m_doc.GetElement(filterId).Name + " -> " + targetTemplate.Name);

                            Ana_NoOfFilters_Applied += 1;       // collect data for analytics
                        }

                        else // IF FILTER ALREADY APPLIED, JUST OVERRIDE GRAPHICS
                        {
                            targetTemplate.SetFilterOverrides(filterId, graphSetting);

                            infoFiltersGraphicOverriden.Add(m_doc.GetElement(filterId).Name + " -> " + targetTemplate.Name);

                            Ana_NoOfFilters_Overriden += 1;     // collect data for analytics
                        }

                        Ana_NoOfFilters_Total += 1;     // collect data for analytics
                    }
                }
                t.Commit();
            }
            executionTime.Stop();
            ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString();     // collect data for analytics
            #endregion

            #region show Results Form
            UI.Info.Form_Results.resultHead  = "Results";
            UI.Info.Form_Results.resultMain1 = "Filters Transferred:";
            UI.Info.Form_Results.resultMain2 = "Filters with Graphic Settings Overriden";
            UI.Info.Form_Results.resultList1 = infoFiltersTransferred;
            UI.Info.Form_Results.resultList2 = infoFiltersGraphicOverriden;

            using (UI.Info.Form_Results thisForm = new Info.Form_Results())
            {
                thisForm.ShowDialog();
            }
            #endregion// show Results Form

            DialogResult = DialogResult.OK;
            useTime.Stop();
            UseTimeElapseS = useTime.Elapsed.Seconds.ToString();    // collect data for analytics
            Utilities.GetAnalyticsCSV(m_doc, m_app);
            Helpers.TransferViewFiltersAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFilters_Total, Ana_NoOfFilters_Applied, Ana_NoOfFilters_Overriden, Ana_NoOfTemplates);
        }