I have a few rogue Viewport Types that cannot be purged, even when no views are placed on sheets, so not truly "used" but still referenced somewhere in the database. I am trying to figure out exactly how they are referenced, and perhaps then change the reference to another type that I do want to keep, so these others can be purged.
I have been able to locate the offending Viewport Type definitions (Autodesk.Revit.DB.ElementType), go back to the model, and Select by Element ID. Manually deleting these Viewport Types takes a large number of my *Schedules* (Autodesk.Revit.DB.ViewSchedule) with them, so I figure that the offending reference must be buried there somewhere.
But, the Autodesk.Revit.DB.ViewSchedule does not seem to have any properties/methods that reference these Viewport Types.
For comparison, when non-schedule views are placed on a sheet, an Autodesk.Revit.DB.Viewport is created, whose GetTypeId() method *will* return the Autodesk.Revit.DB.ElementType ID of the Viewport Type definition.
However, no Autodesk.Revit.DB.Viewport is created for schedule views; only an Autodesk.Revit.DB.ScheduleSheetInstance (and my issue persists with or without ScheduleSheetInstances in the model).
I seem to have quickly hit a dead end, and am unsure where to look from here. Any thoughts?
Perhaps the API doesn't expose what I am trying to find?
Dear bwinterscheidt,
I can indeed well imagine that the API does not provide much heklp on nthis issue. You could take a look at the object relationship analyser:
http://thebuildingcoder.typepad.com/blog/2010/03/object-relationships.html
Here are some examples of using it and the underlying technique:
That might prove a useful tool to support your analysis. More than that, I really don't know. Sounds as if you have done a good job exploring already.
Good luck!
Cheers,
Did you ever find a solution for changing the Viewport Type associated with a schedule? I have 20 schedules that I will need to recreate if not. Ugg
Thanks for replying! I can't make a sample file at the moment, because I'm not at the office, and only have access to Revit 2016 in viewer mode. But this can be tested with any schedule: is it possible to change the Viewport Type associated with a schedule?
Ok if I'm getting you right then this code shall help:
#region Namespaces using System; using System.Text; using System.Linq; using System.Xml; using System.Reflection; using System.ComponentModel; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Forms; using System.IO; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Events; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.UI.Events; using Autodesk.Revit.Exceptions; using Autodesk.Revit.Utility; using RvtApplication = Autodesk.Revit.ApplicationServices.Application; using RvtDocument = Autodesk.Revit.DB.Document; #endregion namespace RevitAddinCS2 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class ExtCmd : IExternalCommand { #region Cached Variables private static ExternalCommandData _cachedCmdData; public static UIApplication CachedUiApp { get { return _cachedCmdData.Application; } } public static RvtApplication CachedApp { get { return CachedUiApp.Application; } } public static RvtDocument CachedDoc { get { return CachedUiApp.ActiveUIDocument.Document; } } #endregion #region IExternalCommand Members public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet) { _cachedCmdData = cmdData; try { FilteredElementCollector collector = new FilteredElementCollector(CachedDoc); collector.OfClass(typeof(Viewport)); List<Viewport> viewports = collector.Cast<Viewport>().ToList(); foreach (Viewport v in viewports) { try { if (v.GetBoxOutline() == null) { CachedDoc.Delete(v.Id); CachedDoc.Delete(v.GetTypeId()); } } catch (Exception ex) { CachedDoc.Delete(v.Id); CachedDoc.Delete(v.GetTypeId()); } } return Result.Succeeded; } catch (Exception ex) { msg = ex.ToString(); return Result.Failed; } } #endregion } }
I also prefer to have a sample RVT file to be ableto reproduce the error.
Have you find a solution for the connection between Viewport Type and Schedule? I have the same problem now... Will be really appreciated if you could share any suggestion.
Thanks,
Yueying
Hi Mustafa.Salaheldin,
Thanks for the quick response. Could you please test the attached RVT?
If I delete the "No Title Copy1" Viewport type, it will delete my "FURNITURE SCHEDULE - A" schedule from my project. So I think there are some hidden connection between schedule and viewport type in Revit. If you can provide a way to change the schedule's "viewport type" to "Section 1", it also works for me.
Thanks so much for your help. Looking forward to your result.
Thanks,
Yueying