Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66664

Re: How can I detect activated view on sheet

$
0
0

my idea in a ExternalCommand

 

//using System.Text;
//using System.Diagnostics;

    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class Fa_ViewStatus : IExternalCommand
    {
        bool ActiveViewIsViewPort(Document doc)
        {
            string uiViewTitle = string.Format("{1} - {0}", doc.Title, doc.ActiveView.Title);
            Process revit = Process.GetCurrentProcess();
            return !revit.MainWindowTitle.Contains(uiViewTitle);
        }

        public StringBuilder sb = new StringBuilder();
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            Document doc = revit.Application.ActiveUIDocument.Document;
            View ActView = doc.ActiveView;
            Type viewType = ActView.GetType();
            sb.AppendLine(string.Format("the active view is {0} [{1}]", ActView.Title, viewType.Name));
            if (ActiveViewIsViewPort(doc))
                {
                //the view is an activated viewport
                    List<Viewport> viewports = new FilteredElementCollector(doc)
                    .OfClass(typeof(Viewport))
                    .Cast<Viewport>().ToList();
                    Viewport activeViewPort = null;
                foreach (Viewport vp in viewports)
                {
                    if (vp.ViewId == ActView.Id) activeViewPort = vp;
                }
                ViewSheet sheet = doc.GetElement(activeViewPort.SheetId) as ViewSheet;
                sb.AppendLine(string.Format("  activated ViewPort of sheet {0}", sheet.Title));
                }
            else
            {
                if (viewType == typeof(ViewSheet))
                {
                    sb.AppendLine("  the sheet has no activated Viewports");
                }
            }

            TaskDialog.Show("ViewStatus", sb.ToString());
            return Result.Succeeded;
        }
    }

 

 


Viewing all articles
Browse latest Browse all 66664

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>