Exemplo n.º 1
0
            /// <summary>
            /// Get Type and Category of Element in the document
            /// </summary>
            /// <param name="doc"></param>
            /// <param name="targetType"></param>
            /// <param name="targetFamilyName"></param>
            /// <param name="targetTypeName"></param>
            /// <param name="targetCategory"></param>
            /// <returns></returns>
            public static Element ElementFiltering(Document doc, Type TargetClass, string TargetFamilyName,
                                                   string TargetTypeName, BuiltInCategory?TargetCategory)

            {
                FilteredElementCollector FECol = new FilteredElementCollector(doc).OfClass(TargetClass);

                if (TargetCategory.HasValue)
                {
                    FECol.OfCategory(TargetCategory.Value);
                }
                var TarElem = from Elem in FECol
                              where Elem.Name.Equals(TargetTypeName) &&
                              Elem.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM)
                              .AsString().Equals(TargetFamilyName)
                              select Elem;
                IList <Element> TargetElems = TarElem.ToList();

                if (TargetElems.Count > 0)
                {
                    return(TargetElems[0]);
                }
                else
                {
                    return(null);
                }
            }