/// <summary>
        /// Return polygon loops representing the size
        /// and location of given sheet and all the
        /// viewports it contains, regardless of type.
        /// </summary>
        static JtLoops GetSheetViewportLoops(
            SheetModelCollections modelCollections,
            ViewSheet sheet)
        {
            Document doc = sheet.Document;

            List <Viewport> viewports = sheet
                                        .GetAllViewports()
                                        .Select <ElementId, Viewport>(
                id => doc.GetElement(id) as Viewport)
                                        .ToList <Viewport>();

            int n = viewports.Count;

            modelCollections.ViewsInSheet[sheet.Id]
                = new List <ViewData>(n);

            JtLoops sheetViewportLoops = new JtLoops(n + 1);

            // sheet.get_BoundingBox( null ) returns (-100,-100),(100,100)

            BoundingBoxUV bb = sheet.Outline;                  // model coordinates (0,0), (2.76,1.95)

            JtBoundingBox2dInt ibb = new JtBoundingBox2dInt(); // millimeters (0,0),(840,...)

            ibb.ExpandToContain(new Point2dInt(bb.Min));
            ibb.ExpandToContain(new Point2dInt(bb.Max));

            JtLoop loop = new JtLoop(ibb.Corners);

            sheetViewportLoops.Add(loop);

            foreach (Viewport vp in viewports)
            {
                XYZ center = vp.GetBoxCenter(); // not used

                Outline outline = vp.GetBoxOutline();

                ibb.Init();

                ibb.ExpandToContain(
                    new Point2dInt(outline.MinimumPoint));

                ibb.ExpandToContain(
                    new Point2dInt(outline.MaximumPoint));

                loop = new JtLoop(ibb.Corners);

                sheetViewportLoops.Add(loop);

                ViewData d = new ViewData();
                d.Id = vp.ViewId;
                d.ViewportBoundingBox = loop.BoundingBox;

                modelCollections.ViewsInSheet[sheet.Id].Add(
                    d);
            }
            return(sheetViewportLoops);
        }