Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We often want to delete all titleblocks from sheets for various reasons. I am trying to create a routine that deletes titleblocks from the model. What I have put together seems to only work if the model only contains 1 family to delete otherwise the model just spins. Any idea what would be causing this?
public void deleteTB()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc= uidoc.Document;
bool deleteStartViewTB = true;
int categoryid = (int)BuiltInCategory.OST_TitleBlocks;
IEnumerable<Family> collector = new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>().Where(q=>q.FamilyCategoryId.IntegerValue==categoryid);
foreach (Family family in collector)
{
using(Transaction T = new Transaction(doc, "Delete titlblock"))
{
try
{
T.Start();
if(deleteStartViewTB)
{
doc.Delete(family.Id);
}
else
{
if(!family.Name.StartsWith("Starting View"))
{
doc.Delete(family.Id);
}
}
T.Commit();
}
catch (Exception ex)
{
TaskDialog.Show("Error", ex.Message);
}
}
}
}
Solved! Go to Solution.