Esempio n. 1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            List <string>            a = new List <string>();
            FilteredElementCollector families;

            #region 3.1.a Retrieve and iterate over all Family objects in document:
            //
            // retrieve all family elements in current document:
            //
            families = new FilteredElementCollector(doc);

            families.OfClass(typeof(Family));

            foreach (Family f in families)
            {
                // Get its category name; notice that the Category property is not
                // implemented for the Family class; use FamilyCategory instead;
                // notice that that is also not always implemented; in that case,
                // use the workaround demonstrated below, looking at the contained
                // family symbols' category:

                a.Add(string.Format("Name={0}; Category={1}; FamilyCategory={2}",
                                    f.Name,
                                    ((null == f.Category) ? "?" : f.Category.Name),
                                    ((null == f.FamilyCategory) ? "?" : f.FamilyCategory.Name)));
            }
            #endregion // 3.1.a

            string msg = "{0} standard familie{1} are loaded in this model{2}";
            LabUtils.InfoMsg(msg, a);

            // Loop through the collection of families, and now look at
            // the child symbols (types) as well. These symbols can be
            // used to determine the family category.

            foreach (Family f in families)
            {
                string catName;
                bool   first = true;

                // Loop all contained symbols (types):

                //foreach( FamilySymbol s in f.Symbols ) // 2014
                foreach (ElementId id in f.GetFamilySymbolIds()) // 2015
                {
                    FamilySymbol s = doc.GetElement(id) as FamilySymbol;

                    // you can determine the family category from its first symbol.

                    if (first)
                    {
                        first = false;

                        #region 3.1.b Retrieve category name of first family symbol:
                        catName = s.Category.Name;
                        #endregion // 3.1.b

                        msg = "Family: Name=" + f.Name
                              + "; Id=" + f.Id.IntegerValue.ToString()
                              + "; Category=" + catName
                              + "\r\nContains Types:";
                    }
                    msg += "\r\n    " + s.Name + "; Id=" + s.Id.IntegerValue.ToString();
                }

                // Show the symbols for this family and allow user to proceed
                // to the next family (OK) or cancel (Cancel)

                msg += "\r\nContinue?";
                if (!LabUtils.QuestionMsg(msg))
                {
                    break;
                }
            }
            //
            // return all families whose name contains the substring "Round Duct":
            //
            IEnumerable <Family> round_duct_families
                = LabUtils.GetFamilies(doc, "Round Duct", true);

            int n = round_duct_families.Count();

            return(Result.Failed);
        }