Filter Element from Linked Model only if visible in active view

Hi all,

I need some help. I’m trying to reduce the range of the action of a script, focusing only on a portion of the project, in order to reduce the runtime.

I really would like to filter all the elements (already filtered by category and contained in a linked file) that are visible in the active view. I already saw and read lots of similar post but none of the solution founded seems to work.

those 3 cable trays are visible… why I don’t have 3 true value in the Elements.IsVisible block??

can’t even find te package of Get Revit.Activeview or Revit Active.view nodes…

I really appreciate some help

Many thanks
Lorenzo

1 Like

test.dyn (7.8 KB) Hope it will help you…

@LorenzoVerde

currently Revit API does not allow this (get link elements from active view)
a workaround is possible with a search for LinkElements by boudingBox or SolidIntersection (CropBox and ViewRange from HostView) without taking into account the different filters that there may be in the view or view template
you can try this node from Data-Shapes
getlinkElements dataShape

1 Like

elements I need are in linked files. In this case this node seems not working…

I also tried this way… can’t understand why I have null as a result…

Hello
try this version

#written by Cyril P
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

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

lnkInstance = UnwrapElement(IN[0])
category = UnwrapElement(IN[1])


transf =lnkInstance.GetTotalTransform()

actView = doc.ActiveView
doclnk = lnkInstance.GetLinkDocument()
#get bootom and top Elevation of active viewrange 
viewRange = actView.GetViewRange()
topClipPlaneId = viewRange.GetLevelId(PlanViewPlane.TopClipPlane) 
topClipPlane = doc.GetElement(topClipPlaneId)
topOffset = viewRange.GetOffset(PlanViewPlane.TopClipPlane)

bttmClipPlaneId = viewRange.GetLevelId(PlanViewPlane.BottomClipPlane) 
bttmClipPlane = doc.GetElement(bttmClipPlaneId)
bttmOffset = viewRange.GetOffset(PlanViewPlane.BottomClipPlane)

bbxActView = actView.CropBox 
#set min and max from active ViewRange
bbxActView.Min = XYZ(bbxActView.Min.X, bbxActView.Min.Y, bttmClipPlane.Elevation + bttmOffset)
bbxActView.Max = XYZ(bbxActView.Max.X, bbxActView.Max.Y, topClipPlane.Elevation + topOffset)
bbxActView.Transform = transf

myOutLn  = Outline(bbxActView.Min, bbxActView.Max)   
#create LogicalOrFilter with BoundingBox 
filterBbxInside = BoundingBoxIsInsideFilter(myOutLn)
filterBbxInters = BoundingBoxIntersectsFilter(myOutLn)
filterBbx = LogicalOrFilter(filterBbxInside, filterBbxInters)
#make collector
fecActiveView = FilteredElementCollector(doclnk).OfCategoryId(category.Id).WherePasses(filterBbx).ToElements()

OUT = fecActiveView
5 Likes

this is great! but if I understood well… it works only with plan views… not with 3D view…
I would have to run the script floor by floor… or does it takes the volume of the section box?

For 3D views, you can use the SelectByCategoryAndHost3DView node.
SelectByCategoryAndHost3DView

3 Likes

which is its package? “Genius Loci” ?

yes

1 Like

Could it be possible that it doesn’t work if you run this node in a central cloud model with different workset?
If I run it in a deattached model everything is fine without workset…
if I run it in a cloud central model, the filter of elements doesn’t work properly…

It is working fine with models with worksets:

Some nodes could be disturbed but I don’t currently have a cloud project and therefore can’t verify that it is working properly.
How do you select the linked document ? Can you show a screenshot with previews enabled under the nodes ?

@c.poupin the script is not selecting keynote tags! Is there any possible way to do that?

The script is not compatible with IndependentTag, a workaround will be to collect the physical elements of the linked model (via the script above) then to find the keynote tags attached to them.

as a reminder the script is already a workaround because currently Revit API does not allow get link elements from active view

2 Likes

Thank you! Will try as you suggested!

1 Like

This is a great solution, thank you c.poupin
Is it possible to run the graph without having to refresh it?

when the view changed or the cropbox of view changed ?

Thanks for the quick reply.
I adjusted your workaround in order to collect all the pipes from a link model, filter them by a parameter (Revision comment) and place a revision cloud on them. I tried other ways to get them but only yours worked so thank you for that. Every time I run the script on another view or level it refreshes it and removes the already placed clouds from other views. I’d like to keep them. The problem might be from the SpringsUI.Refresh node that I’m using (it’s a bit crashy and weird) but I don’t have another refresh button due to mix of version of dynamo and versions of packages that are barely holding up.

Would a workaround in the python script remove the need for a refresh node?

Are you trying with DynamoPlayer?

No, I’m opening Dynamo, so I can adjust the revision numbers.