How to collect elements from links visible on a view in the host model?

This didn’t work for me.

https://forum.dynamobim.com/t/to-push-element-type-parameters-into-shared-parameters-for-rooms/5846/9

In this link we were arguing about getting the job done in pieces. (room numbers into element numbers). But I have 1000 rooms in linked file and doing a cross product intersect check takes a long time.

@Greg_McDowell suggested to do it chunks, and I thought if I can get the rooms from linked model by view specific properties, then I could do it. But I get the same error like @Swapnil_Raut.

Do you have any other suggestions? All I want to do is to make a cross check between rooms in a linked file view and the host file floors.

Hi @Cem_Altineller ,
have you tried this code ?

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
import System
from System.Collections.Generic import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import*
doc = DocumentManager.Instance.CurrentDBDocument

#Inputs
category = IN[2]
linkdoc = IN[1]
views = UnwrapElement(IN[0])

collector = []

#getting project base point elevation
basepointfilter = ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint)
basepoint = FilteredElementCollector(doc).WherePasses(basepointfilter).ToElements()
bpelevation = [b.ParametersMap.get_Item('Elev').AsDouble() for b in basepoint]

#Category filter
catfilter = ElementCategoryFilter(System.Enum.ToObject(BuiltInCategory,category.Id))

UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
level = []
for v in views:

	#creating a boundingbox for each view from it's crop box and view range
	bb = v.CropBox
	vr = v.GetViewRange()
	topclip = PlanViewPlane.TopClipPlane
	bottomclip = PlanViewPlane.BottomClipPlane
	cutclip = PlanViewPlane.CutPlane
	toplevel = (doc.GetElement(vr.GetLevelId(topclip)))
	topoffset = vr.GetOffset(topclip)
	cutlevel = (doc.GetElement(vr.GetLevelId(cutclip)))
	cutoffset = vr.GetOffset(cutclip)
	try:
		topZ = toplevel.Elevation + topoffset - bpelevation[0]
	except:
		topZ = cutlevel.Elevation + cutoffset - bpelevation[0]
	bottomlevel = (doc.GetElement(vr.GetLevelId(bottomclip)))
	bottomoffset = vr.GetOffset(bottomclip)
	try:
		bottomZ = bottomlevel.Elevation + bottomoffset - bpelevation[0]
	except :
		bottomZ = cutlevel.Elevation - bpelevation[0]
	min = bb.Min
	max = bb.Max
	newmin = XYZ(UnitUtils.ConvertToInternalUnits(min.X,UIunit),UnitUtils.ConvertToInternalUnits(min.Y,UIunit),bottomZ)
	newmax = XYZ(UnitUtils.ConvertToInternalUnits(max.X,UIunit),UnitUtils.ConvertToInternalUnits(max.Y,UIunit),topZ)
	ol = Outline(newmin,newmax)

	#combining boundingbox and category filters
	bbfilter = BoundingBoxIntersectsFilter(ol)
	andfilter = LogicalAndFilter(catfilter,bbfilter)

	#collecting elements
	collector.append(FilteredElementCollector(linkdoc).WherePasses(andfilter).ToElements())

OUT = collector

Yes sir, I did.

It gave me this error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 65, in
TypeError: expected Document, got UnknownElement

And this is the screenshot for the visual code. By select model element I was selecting the linked file with rooms in it.

This code expects an Autodesk.Revit.DB.Document input.Try getting the linked document like this :

How does x[0] codeblock work? How do I choose a particular link amongst many? Is it x[1], x[2] etc or y[0], z[0] etc?

x[0] just means first item of list x. It’s the same as :

look at your List of linked documents and get the one you’re interested in.

Ok, thanks getting that out of the way. Learned a very important thing thanks to you sir.

After finding the right link in my file the code worked, but it returns empty list. Uploaded what I’ve done in the screenshot.

Hi @Cem_Altineller ,

there are some unnecessary units conversions on that code that cause trouble. I fixed it and wrapped it in a node in the Data-Shapes packages :


Inputs are fine, but output is still empty. It is so close:)

Hi @Mostafa_El_Ayoubi

I used the same nodes as you showED, but it showed to me only host elements and nothing for linked elements.

Thank You

@Mohammad_Nawar , @Cem_Altineller ,
could you share a dummy version of your files so I can take a look at them?

I was testing on dummy projects and these the Revit files.

Project 1: is the linked model
project 2: is the host model

@Mohammad_Nawar thanks! this will help narrow down the issue faster.

I just tested your file and all seems to actually be working fine :


the elements the node outputs are from the linked file.

1 Like

Yeah u r right

It showing the linked elements, Sry my mistake

No worries , this node is based on a workaround that will probably show it’s limits at some point. I’m very eager to find out so don’t hesitate if you see something :smile:

1 Like

HI,
I’ve the same problem. I need to collect the walls of Linked model.
I built the script that you have showed in previous replies, ma dynamo shows an “Empty list”.
what could be the problem? Thanks

Does this script works with 3D views? Can’t get it work…

Hope to hear from u!

Same error here. Any news about the Empty List issue?

Hello Mustafa,
Do you know why Getlinkelemeninhostviewandcategory on your package does not work?
I have noticed the inputs in the node are not in the same order as the custom node, could this be related???

hello @Mostafa_El_Ayoubi I tried the nodes of Data-Shapes, and it only works with floor plan views, I want to do it with Axonometric 3D views! Do you know how to fix it? Thanks