Exemple #1
0
        /// <summary>
        /// Get the view crop element and crop region curves
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        internal static ViewCrop GetViewCrop(Autodesk.Revit.DB.View view)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            ViewCrop viewCrop;

            using (SubTransaction tGroup = new SubTransaction(doc))
            {
                tGroup.Start();

                using (SubTransaction t1 = new SubTransaction(doc))
                {
                    // Deactivate crop box
                    t1.Start();
                    view.CropBoxVisible = false;
                    t1.Commit();
                    doc.Regenerate();

                    // Get all visible elements, which does not include the crop box
                    FilteredElementCollector collector  = new FilteredElementCollector(doc, view.Id);
                    ICollection <ElementId>  shownElems = collector.ToElementIds();

                    // Activate the crop box
                    t1.Start();
                    view.CropBoxVisible = true;
                    t1.Commit();
                    doc.Regenerate();

                    // Get all visible elements, excluding everything but the crop box
                    collector = new FilteredElementCollector(doc, view.Id);
                    collector.Excluding(shownElems);

                    viewCrop.cropElement = collector.FirstElement();
                    viewCrop.cropRegion  = view.GetCropRegionShapeManager().GetCropShape().First();
                }
                tGroup.RollBack();
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(viewCrop);
        }