Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm trying to delete all of my views (not including sheets at this point) but despite everything running as expected, the views continue to be in the model.
I've done quite a bit of research and also tried refreshing my project browser as I know some actions need that (such as renaming views) but no success either.
I'm basically trying to isolate the callout view parents and the dependent view parents so they are deleted last otherwise I run into an error saying the element doesn't exist (if you delete the parent first, the callout also gets deleted).
This is a sample of the code.
var viewsToDelete = new List<ElementId>();
var parentViews = new List<ElementId>();
var allViews = new FilteredElementCollector(doc).
OfClass(typeof(View)).
WhereElementIsNotElementType().
ToElements();
foreach (View view in allViews)
{
ElementId parentId = view.GetPrimaryViewId();
if (parentId.IntegerValue == -1 && !view.IsTemplate && !view.IsCallout)
{
// View is NOT a dependent
viewsToDelete.Add(view.Id);
continue;
}
else if (parentId.IntegerValue != -1 && !view.IsTemplate && !view.IsCallout)
{
// View is dependent
parentViews.Add(view.GetPrimaryViewId());
continue;
}
else if (view.IsTemplate)
{
// View is template
continue;
}
else if (view.IsCallout && !parentViews.Contains(view.GetCalloutParentId()))
{
// View is callout
parentViews.Add(view.GetCalloutParentId());
}
else
{
console.ShowBoldMessage($"Could not find classification for view {view.Id}");
}
}
foreach (var viewId in parentViews)
{
viewsToDelete.Add(viewId);
}
foreach (var elemId in viewsToDelete)
{
try
{
doc.Delete(elemId);
}
catch
{
console.ShowMessage($"Could not delete element {elemId}");
continue;
}
}
Solved! Go to Solution.
