コード例 #1
0
        /// <summary>
        /// Return parameter data for all
        /// elements of all the given categories
        /// </summary>
        static void GetParamValuesForCats(
            Dictionary <string, Dictionary <string, List <string> > >
            map_cat_to_uid_to_param_values,
            Document doc,
            BuiltInCategory[] cats)
        {
            // One top level dictionary per category

            foreach (BuiltInCategory cat in cats)
            {
                map_cat_to_uid_to_param_values.Add(
                    cat.Description(),
                    new Dictionary <string,
                                    List <string> >());
            }

            // Collect all required elements

            // The FilterCategoryRule as used here seems to
            // have no filtering effect at all!
            // It passes every single element, afaict.

            List <ElementId> ids
                = new List <BuiltInCategory>(cats)
                  .ConvertAll <ElementId>(c
                                          => new ElementId((int)c));

            FilterCategoryRule r
                = new FilterCategoryRule(ids);

            ElementParameterFilter f
                = new ElementParameterFilter(r, true);

            // Use a logical OR of category filters

            IList <ElementFilter> a
                = new List <ElementFilter>(cats.Length);

            foreach (BuiltInCategory bic in cats)
            {
                a.Add(new ElementCategoryFilter(bic));
            }

            LogicalOrFilter categoryFilter
                = new LogicalOrFilter(a);

            // Run the collector

            FilteredElementCollector els
                = new FilteredElementCollector(doc)
                  .WhereElementIsNotElementType()
                  .WhereElementIsViewIndependent()
                  .WherePasses(categoryFilter);

            // Retrieve parameter data for each element

            foreach (Element e in els)
            {
                Category cat = e.Category;
                if (null == cat)
                {
                    Debug.Print(
                        "element {0} {1} has null category",
                        e.Id, e.Name);
                    continue;
                }
                List <string> param_values = GetParamValues(e);

                BuiltInCategory bic = (BuiltInCategory)
                                      (e.Category.Id.IntegerValue);

                string catkey = bic.Description();
                string uid    = e.UniqueId;

                map_cat_to_uid_to_param_values[catkey].Add(
                    uid, param_values);
            }
        }
コード例 #2
0
        SiphonElementParamValues(
            this Document doc,
            out Dictionary <int, string> legend,
            bool calculateCentroids     = true,
            List <BuiltInCategory> cats = null)
        {
            if (cats == null)
            {
                cats = ConfigurationManager.ActiveConfiguration.ExportedCategories;
            }

            // Set up the return value dictionary
            var map_cat_to_uid_to_param_values
                = new Dictionary <string,
                                  Dictionary <string,
                                              Dictionary <string, string> > >();

            // One top level dictionary per category
            foreach (BuiltInCategory cat in cats)
            {
                map_cat_to_uid_to_param_values.Add(
                    cat.Description(),
                    new Dictionary <string,
                                    Dictionary <string, string> >());
            }

            // Collect all required elements
            var els = doc.ExportableElements();

            // Retrieve parameter data for each element
            var legendReversed = new Dictionary <string, int>();

            legendReversed.Add("Category", 0);
            if (calculateCentroids)
            {
                legendReversed.Add("Centroid", 1);
            }

            foreach (Element e in els)
            {
                Category cat = e.Category;
                if (null == cat)
                {
                    continue;
                }
                Dictionary <string, string> param_values = GetParamValues(e, ref legendReversed);

                if (calculateCentroids &&
                    e.TryGetCentroid(DefaultExportGeometryOptions, out var c))
                {
                    param_values.Add("1", c.Centroid_Str);
                }

                BuiltInCategory bic = (BuiltInCategory)
                                      (e.Category.Id.IntegerValue);

                string catkey   = bic.Description();
                string uniqueId = e.UniqueId.ToString();

                map_cat_to_uid_to_param_values[catkey].Add(
                    uniqueId, param_values);
            }

            legend = legendReversed.ToDictionary(kv => kv.Value, kv => kv.Key);


            return(map_cat_to_uid_to_param_values);
        }