예제 #1
0
        public void Execute(UIApplication uiApp)
        {
            #region LoggerSetup
            //Nlog configuration
            var nlogConfig = new NLog.Config.LoggingConfiguration();
            //Targets
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "g:\\log.txt", DeleteOldFileOnStartup = true
            };
            //Rules
            nlogConfig.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
            //Apply config
            NLog.LogManager.Configuration = nlogConfig;
            //DISABLE LOGGING
            NLog.LogManager.DisableLogging();
            #endregion

            Document   doc   = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            Selection selection = uidoc.Selection;

            FilteredElementCollector col = new FilteredElementCollector(doc);

            //Test to see if catfilter is populated
            if (Payload.CategoriesToSearch.Count < 1)
            {
                return;
            }

            List <ElementFilter> catFilter = new List <ElementFilter>();
            if (Payload.CategoriesToSearch.Contains("Pipe Fittings"))
            {
                catFilter.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeFitting));
            }
            if (Payload.CategoriesToSearch.Contains("Pipe Accessories"))
            {
                catFilter.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeAccessory));
            }
            if (Payload.CategoriesToSearch.Contains("Pipes"))
            {
                catFilter.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves));
            }

            col.WherePasses(new LogicalAndFilter(new List <ElementFilter>
            {
                new LogicalOrFilter(catFilter),
                new LogicalOrFilter(new List <ElementFilter>
                {
                    new ElementClassFilter(typeof(Pipe)),
                    new ElementClassFilter(typeof(FamilyInstance))
                })
            }));

            //selection.SetElementIds(col.ToElementIds());

            Payload.ElementsInSelection = new HashSet <ElementImpression>
                                              (col.Select(x => new ElementImpression(x, Payload.Grouping)));
            Payload.RaiseSnSOperationComplete();
        }