We discussed the loading of a single family type just two days ago. Here is a related question that came up and was handled by Saikat Bhattacharya:
Question: How can I use the API to remove unused family types from a project? I know there is a command within Revit to do this, but we would like to automate the process.
Answer: You can unload a specific loaded family symbol from your project using the Document.Delete() method. I tested this as follows:
- Load a specific column symbol "457 x 610mm".
- Run an external command with the code below to filter out and iterate over all column elements, including symbols.
- Apply the Delete method to remove and thus unload the specific symbol.
After running the code, the list of loaded family symbols displayed in the user interface confirmed that the specific family symbol was no longer present in the project. Here is the code for the external command Execute method:
public IExternalCommand.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { Application app = commandData.Application; Document doc = app.ActiveDocument; Filter filter = app.Create.Filter.NewCategoryFilter( BuiltInCategory.OST_Columns ); ElementIterator it = doc.get_Elements( filter ); while ( it.MoveNext() ) { Element e = it.Current as Element; if ( e.Name.Equals( "457 x 610mm" ) ) { doc.Delete( e ); } } return IExternalCommand.Result.Succeeded; }
Thank you Saikat for this solution!
1. And if I want to Delete Family along with all Family Types in it. How can I do that?
2. How can I List all families in One Collection Including All Ducts and Pipes also?
Many thanks.
Yasir
Posted by: Yasir | October 08, 2010 at 20:28
Dear Yasir,
1. You can use the Document.Delete method. Its use in this context is described in
http://thebuildingcoder.typepad.com/blog/2009/06/unload-family-type.html
2. That sounds like a pretty weird request to me, but it is still doable:
List.lt.ElementFilter.gt. a
= new List.lt.ElementFilter.gt.( 3 );
a.Add( new ElementClassFilter(
typeof( Family ) ) );
a.Add( new ElementClassFilter(
typeof( Duct ) ) );
a.Add( new ElementClassFilter(
typeof( Pipe ) ) );
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.WherePasses( new LogicalOrFilter( a ) );
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 10, 2010 at 13:42