What sheets are my views on?

A reader asked: How do u find out what sheet a view is on via API?

Below is some code and the screenshot shows the Project Browser and output from the API macro.

ViewSheetReport

public void viewSheetReport()
{
    Document doc = this.ActiveUIDocument.Document;
    string data = "";
    foreach (View v in new FilteredElementCollector(doc).OfClass(typeof(View)))
    {
        string thisSheet = "";
        foreach (ViewSheet vs in new FilteredElementCollector(doc)
            .OfClass(typeof(ViewSheet))
            .Cast<ViewSheet>())
        {
            foreach (View view in vs.Views)
            {
                if (view.Id == v.Id)
                {
                    thisSheet += vs.Name + " - " + vs.SheetNumber + ", ";
                    break;
                }
            }
        }
        if (thisSheet != "")
        {
            data += v.ViewType + " - " + v.Name + ": " + thisSheet.TrimEnd(' ',',') + Environment.NewLine + Environment.NewLine;
        }
    }
    TaskDialog.Show("Sheet Report", data);
}
Advertisements

3 thoughts on “What sheets are my views on?

  1. Also, if you just need the sheet number you could use something like:
    string sheetNum = view.get_Parameter(“Sheet Number”).AsString();

  2. Harry,

    Great write up. I am only curious about one little thing:
    when you call vs.Views its throwing an error on my machine. I checked SDK for 2016 and there is no such Property for ViewSheet. Instead I noticed that it can be replaced with vs.GetAllPlacedViews() which then can be used with doc.GetElement() to obtain all Views on a sheet.
    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s