Find views and sheets that show a specific element

Hello,

this looks promising and I want to try it, however, isn’t it a kind of “brute force” approach?

I mean, has anyone trying this on a project with hundreds of views and sheets?

 

Thank you!

Gio

I just did this method, generally, on a project with nearly 1,000 views and it took far too long. I’d like to see if there is a way to only have it crawl the views for a specific element type, or even a specific element, without collecting them all and then filtering.

I know that it is not exactly what you’re looking for but we had a go at this a while ago for all elements visible on sheet. I made one script, Dimitar V did it better, as shown below. Maybe you can use it for further development? Anyways, it would be cool if someone could try it on a larger project.

Greg-

I am sure that my little script can be made to run more efficiently by tinkering with the loops and the order of the loops (I know it can…I’m just not able to make the edits and test right now).

That said, the OP stated that they were looking to find ALL views and sheets that showed a particular element or elements. That means you must collect all of the views and test each one to see if your element is visible. If you want to limit it to just plan views, or views on sheets, or any other subset of views then obviously the script will run faster, but it will not produce ALL views that show an element.

I do think that what you suggested regarding limiting the elements in view collectors to a particular category would be wise and help a lot in the speed.

I think this iteration through all views/elements is unavoidable

but I am wondering if ‘highlight in model’ is accessible via the API & if this would be more efficient or eliminate some csutom code ?

i.e when you select an element in a schedule

Andrew

 

20160321 Revit find object in view

Andrew

1 Like

So I revisited the python script and made some changes (circled in red) that seemed to help the speed.

I tested this on a real project model (30 story bldg) with 1500 views, 100+ sheets, etc…

For a single element, it took between 3 and 4 seconds to find 73 views and 17 sheets that had that element visible. I then selected 240 elements and pressure tested it - it took 11 minutes to find all views and sheets with each of those elements visible (not a running list of views but a unique list for each of the 240 elements).

For comparison, the previous script took about 5 minutes for a single element on this same model…

3 Likes

I found a faster way without writing any Python myself.

First, get a list of all elements of a certain type in the model (Element.AllInstances). Then query which view owns the elements (Element.OwnerView). Finally, compare (List.Contains) the IDs of these views with the IDs of all views (List All Views) and filter the list of all views by the boolean mask of the comparison.

The Phyton you shared is probably faster but this worked too.

Greg-

I think Element.OwnerView only works for 2D elements (Text, Detail items, Etc…). Model Elements do not appear have an “OwnerView”. So you approach works great (and likely faster than the Python) as long as the Types are not 3D elements…

Good to know! Yes, I was looking for 2D items so it worked well. I’ll have to keep your code bookmarked for when I need something for model elements… unless someone puts a node in the Package Manager first! :wink:

would it be possible to compare only views that are on sheets?

Hi, I’ve tested Ben’s Python Script and works perfectly. I’m quite newbie here with python coding so, I would like to ask if it is possible to make this work with elements from a linked file? I got only empty lists if i add to the Input elements from the “Get All Elements From Linked Model” node.
Thank you very much.

Element_Sheets.dyn (27.9 KB)

Any chance this image can be reposted? Can’t make it out…

2 Likes

Thanks to all of the responses and ideas. I was trying to find all floor plan views NOT on sheets that had instances of a specific detail line type.

I would imagine this could be extended to look for other things in other views.

Find All Views Not on Sheets Containing Instance of a Specific Line Style.dyn (30.5 KB)

… and of curse Revit enters into a long loop that we cannot wait for (it looks like it’s regenerating every view in the project… not good), and we have to quit the application.

Quite amazing how still there is no way to interrupt a Dynamo script: it’s almost 2023 guys…

But thank you for the community inputs, you guys are great.

Regards

Hi guys
I see this is an old post, but you can write the script more efficiently. FilterElementCollector has more filtering options with which you can narrow down the selection and you don’t have to iterate through all the elements.

But it will have its limitations:
1.) FilterElementCollector finds only visible elements in the view
2). FilterElementCollector also selects elements that may not be visible but are actually on the view, which is caused by the view range setting

It would be easiest to narrow down the selection for filtered views, for example using the view type (Elevation, CeilingPlan, etc.), name or sorting parameter in the project browser.

I’m saving it here as a reminder to write it more efficiently.

Is this a node or a Pyton command?

thank you

Thank you Hamish,
seems it could help in this thread’s topic, but python methods are above and beyond what I can reasonably manage… :frowning:

For all in this thread, I made a Dynam script, which uses the node “all elements of category in view” at its core, to produce the wanted result, namely, it finds all sheets and views where a selected element is visible.

The node seems to be forcing the regeneration of all views fed to it, which I think it is equivalent to opening every view and looking for the element.

I setup the script to screen sheets and also allow te user to reduce the number of sheets to run tests and limit the run time.

Then the script exports the sheet and view found onto an Excel table.

This works with the Player.

I hope it helps someone.

try this.

The script narrows the selection to only the category of the selected element.
Searches in BuiltInCategory.OST_Views and BuiltInCategory.OST_Sheets view category

If you don’t need both, just remove one and the script will run even faster.

import clr,System
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

from System import Array
from System.Collections.Generic import *

element = UnwrapElement(IN[0])
elementId = element.Id
elemCatName = element.Category.Name

#Get element BuiltInCategory
bic = System.Enum.GetValues(BuiltInCategory) 
cats, bics = [], []
for i in bic:
    try:
        cat = Revit.Elements.Category.ById(ElementId(i).IntegerValue)
        cats.append(cat)
        bics.append(i)
    except:
        pass
 
for i, b in zip(cats, bics):
    if elemCatName == str(i): 
        ost = b 

#Filter View
cat_list = [BuiltInCategory.OST_Views, BuiltInCategory.OST_Sheets]
typed_list = List[BuiltInCategory](cat_list)
filter = ElementMulticategoryFilter(typed_list)
views = FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()

output = list()

for v in views:

	if v.IsTemplate:
		continue
		
	elementsCol = FilteredElementCollector(doc,v.Id).OfCategory(ost).WhereElementIsNotElementType().ToElementIds()
	if elementId in elementsCol:
		output.append(v)

OUT = output

ok I tested it on a large project and it’s quite overkill for Revit… :sweat_smile: :grinning: