Category GetCategory( Document doc, BuiltInCategory target) { Category cat = null; if (target.Equals(BuiltInCategory.OST_IOSModelGroups)) { // determine model group category: FilteredElementCollector collector = Util.GetElementsOfType(doc, typeof(Group), // GroupType works as well BuiltInCategory.OST_IOSModelGroups); IList <Element> modelGroups = collector.ToElements(); if (0 == modelGroups.Count) { Util.ErrorMsg("Please insert a model group."); return(cat); } else { cat = modelGroups[0].Category; } } else { try { cat = doc.Settings.Categories.get_Item(target); } catch (Exception ex) { Util.ErrorMsg(string.Format( "Error obtaining document {0} category: {1}", target.ToString(), ex.Message)); return(cat); } } if (null == cat) { Util.ErrorMsg(string.Format( "Unable to obtain the document {0} category.", target.ToString())); } return(cat); }
Category GetCategory( Document doc, BuiltInCategory target) { Category cat = null; if( target.Equals( BuiltInCategory.OST_IOSModelGroups ) ) { // determine model group category: FilteredElementCollector collector = Util.GetElementsOfType( doc, typeof( Group ), // GroupType works as well BuiltInCategory.OST_IOSModelGroups ); IList<Element> modelGroups = collector.ToElements(); if( 0 == modelGroups.Count ) { Util.ErrorMsg( "Please insert a model group." ); return cat; } else { cat = modelGroups[0].Category; } } else { try { cat = doc.Settings.Categories.get_Item( target ); } catch( Exception ex ) { Util.ErrorMsg( string.Format( "Error obtaining document {0} category: {1}", target.ToString(), ex.Message ) ); return cat; } } if( null == cat ) { Util.ErrorMsg( string.Format( "Unable to obtain the document {0} category.", target.ToString() ) ); } return cat; }