public static Preview OrderNew(GeometricElement element) { if (!element.IsValid) { return(null); } if (previewsQueue is null) { previewsQueue = new List <Preview>(); Revit.EnqueueReadAction((doc, cancel) => BuildPreviews(doc, cancel)); } var preview = new Preview(element); previewsQueue.Add(preview); return(preview); }
static void BuildPreviews(DB.Document document, bool cancelled, List <Preview> previews) { if (cancelled) { return; } var stopWatch = new Stopwatch(); int count = 0; while ((count = previews.Count) > 0) { // Draw the biggest elements first. // The biggest element ia at the end of previews List, this way no realloc occurs when removing it int last = count - 1; var preview = previews[last]; previews.RemoveAt(last); stopWatch.Start(); preview.Build(document); stopWatch.Stop(); // If building those previews take use more than 200 ms we return to Revit, to keep it 'interactive'. if (stopWatch.ElapsedMilliseconds > 200) { break; } } // RhinoDoc.ActiveDoc.Views.Redraw is synchronous :( // better use RhinoView.Redraw that just invalidate the view, the OS will update it when possible foreach (var view in Rhino.RhinoDoc.ActiveDoc.Views) { view.Redraw(); } // If there are pending previews to generate enqueue BuildPreviews again if (previews.Count > 0) { Revit.EnqueueReadAction((doc, cancel) => BuildPreviews(doc, cancel, previews)); } }