//get sheets in project
FilteredElementCollector sheets = new FilteredElementCollector(uidoc.Document).OfClass(typeof(ViewSheet));
//find revisions on sheets
foreach (ViewSheet sheet in sheets)
{
//get the clouds drawn directly on the sheet
View sheetView=uidoc.Document.GetElement(sheet.Id) as View;
getCloudDataInView(sheetView, sheet, null);
//first get the viewports to get the detail number and "name on sheet" if different than view name
// then get the view from the viewport to get the clouds drawn within each placed view of the sheet
ICollection<ElementId> vpIDs=sheet.GetAllViewports();
foreach (ElementId vpID in vpIDs)
{
Viewport viewport = uidoc.Document.GetElement(vpID) as Viewport;
View view = uidoc.Document.GetElement(viewport.ViewId) as View;
getCloudDataInView(view, sheet, viewport);
}
}
//find revisions NOT on sheets
FilteredElementCollector allInstances = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_RevisionClouds).OfClass(typeof(RevisionCloud));
IList<Element> clouds = allInstances.ToElements();
foreach (RevisionCloud cloud in clouds)
{
if (cloud.GetSheetIds().Count==0)
{
//make sure the cloud hasn't already been found on a sheet
if (revsProcessed.Contains(cloud.Id))
{
//do nothing
}
else
{
RevisionData rev = new RevisionData(cloud, null, null);
revsList.Add(rev.SortString, rev);
}
}
}
If you go through the project sheet by sheet, you fail get any clouds that aren't on sheets. I wanted those too so I could check for drafting errors. So, as I processed each sheet, I use this method below to collect a list of clouds that had already been processed. Afterwards I collected all the clouds and check to see if they were NOT on the list.
private void getCloudDataInView(Autodesk.Revit.DB.View view, ViewSheet sheet, Viewport viewport)
{
FilteredElementCollector clouds;
clouds = new FilteredElementCollector(view.Document, view.Id).OfCategory(BuiltInCategory.OST_RevisionClouds).OfClass(typeof(RevisionCloud));
foreach (RevisionCloud cloud in clouds)
{
RevisionData rev = new RevisionData(cloud, sheet, viewport);
revsList.Add(rev.SortString, rev);
revsProcessed.Add(cloud.Id);
}
}