public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; FilteredElementCollector collector = LabUtils.GetFamilySymbols(doc, BuiltInCategory.OST_Columns); #region Test explicit LINQ statement and cast #if USE_EXPLICIT_LINQ_STATEMENT var column_types = from element in collector where element.Name.Equals("475 x 610mm") select element; FamilySymbol symbol = column_types .Cast <FamilySymbol>() .First <FamilySymbol>(); #endif // USE_EXPLICIT_LINQ_STATEMENT #if CAST_TO_FAMILY_SYMBOL FamilySymbol symbol = collector.First <Element>( e => e.Name.Equals("475 x 610mm")) as FamilySymbol; #endif // CAST_TO_FAMILY_SYMBOL #endregion // Test explicit LINQ statement and cast Element symbol = collector.First <Element>( e => e.Name.Equals("475 x 610mm")); using (Transaction t = new Transaction(doc)) { t.Start("Delete Family Type"); //doc.Delete( symbol ); // 2013 doc.Delete(symbol.Id); // 2014 t.Commit(); } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; // retrieve all FamilySymbol objects of "Windows" category: BuiltInCategory bic = BuiltInCategory.OST_Windows; FilteredElementCollector symbols = LabUtils.GetFamilySymbols(doc, bic); List <string> a = new List <string>(); foreach (FamilySymbol s in symbols) { Family fam = s.Family; a.Add(s.Name + ", Id=" + s.Id.IntegerValue.ToString() + "; Family name=" + fam.Name + ", Family Id=" + fam.Id.IntegerValue.ToString()); } LabUtils.InfoMsg("{0} windows family symbol{1} loaded in the model{1}", a); // loop through the selection set and check for // standard family instances of "Windows" category: int iBic = (int)bic; string msg, content; ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); foreach (ElementId id in ids) { Element e = doc.GetElement(id); if (e is FamilyInstance && null != e.Category && e.Category.Id.IntegerValue.Equals(iBic)) { msg = "Selected window Id=" + e.Id.IntegerValue.ToString(); FamilyInstance inst = e as FamilyInstance; #region 3.3 Retrieve the type of the family instance, and the family of the type: FamilySymbol fs = inst.Symbol; Family f = fs.Family; #endregion // 3.3 content = "FamilySymbol = " + fs.Name + "; Id=" + fs.Id.IntegerValue.ToString(); content += "\r\n Family = " + f.Name + "; Id=" + f.Id.IntegerValue.ToString(); LabUtils.InfoMsg(msg, content); } } return(Result.Succeeded); }