Manual elements selection in python

Hello,
I have a script that finds intersections between pipes and walls (in revit link). He checks all the walls with all the pipes and it good works on small projects, but not on large ones.
I’m trying to change it and I want to manually set the items to check. For example, select some pipe instances in Revit and find intersections only for them … or select a wall in a linked file and find all the pipes that intersect with it.
I try method UnwrapElements and collector for active view, but i don’t understand how it work.

# Filtering related files
if isLink:
a = 0
for inst in linkInstances:
if nameLink in inst.Name:
linkDoc = inst.GetLinkDocument ()
a = 1
if a == 0:
linkDoc = doc
else:
linkDoc = doc

# Getting a collection of all copies of the walls
walls = FilteredElementCollector (linkDoc) .OfCategory (BuiltInCategory.OST_Walls) .WhereElementIsNotElementType (). ToElements ()

# Opening a transaction
TransactionManager.Instance.EnsureInTransaction (doc)

# Activation of loaded families of openings (if not used yet)
rectnOpen.Activate ()
roundOpen.Activate ()

# Processing the list of wall instances
for wall in walls:
# Getting the width
width = wall.Width

# Getting the coefficients of the equation of a line
wallCurve = wall.Location.Curve # Getting the curve of a wall sketch
endWall0 = wallCurve.GetEndPoint (0) # Getting the starting point of a curve
endWall1 = wallCurve.GetEndPoint (1) # Getting the end point of a curve
x0 = endWall0.X; y0 = endWall0.Y; x1 = endWall1.X; y1 = endWall1.Y # Get individual coordinates of points
A1 = y0-y1; B1 = x1-x0 # Getting the coefficients of the equation of a straight line

# Getting the wall geometry
geomElem = wall.get_Geometry (opt)
for geomObj in geomElem:
geomSolid = geomObj

# Receiving a collection of all pipe instances in the project (it is necessary to take each time again)
pipes = FilteredElementCollector (doc) .OfCategory (BuiltInCategory.OST_PipeCurves) .WhereElementIsNotElementType ()
# Extract only those that intersect with the volume of the wall
pipeInters = pipes.WherePasses (ElementIntersectsSolidFilter (geomSolid)). ToElements ()

# Formation of an empty intermediate list
_lst = []

# Processing of pipes intersecting with this wall
for pipe in pipeInters:
result = creation (pipe, width)
_lst.append (result)

lst.append (_lst)

# Closing a transaction
TransactionManager.Instance.TransactionTaskDone ()

OUT = lst

Please use the </> option to correctly format your code when you paste it.
It should look like this in the preview window.

1 Like

It looks like your if statement gives you the same results. Assuming “doc” is the current document and not the link this is where it may be breaking to start with.
2138256162