# How to run task of Geometry.DoesIntersect with Python code in Dynamo?

**URL:** <https://forum.dynamobim.com/t/how-to-run-task-of-geometry-doesintersect-with-python-code-in-dynamo/88400>\
**Category:** Revit\
**Tags:** revit, python, geometry, dynamo\
**Created:** [April 11, 2023, 8:20am UTC](https://forum.dynamobim.com/t/how-to-run-task-of-geometry-doesintersect-with-python-code-in-dynamo/88400 "2023-04-11T08:20:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubenVivancos](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/rubenvivancos/32/185795_2.png) [@RubenVivancos](https://forum.dynamobim.com/u/RubenVivancos)\
**Post date:** [April 11, 2023, 8:20am UTC](https://forum.dynamobim.com/t/how-to-run-task-of-geometry-doesintersect-with-python-code-in-dynamo/88400/1 "2023-04-11T08:20:31Z")

</div>

How to run task of Geometry.DoesIntersect with Python code in Dynamo? I am using the OOTB node Geometry.DoesIntersect, it works but takes ages!! so I would like to run a similar task but using Python in Dynamo instead.

In this example I got a first list of Solids geometry and I want to check if a second list of other geometry that can be a point, line, solid is intersecting with each Solid of the first list.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/0/e0c0d7300b506418f518ea79f43ac6c6197f8b64.png)

I tried this but I wonder if there is better way to handle this:

```auto
import clr
clr.AddReference('RevitAPI') # Add reference to Revit API
from Autodesk.Revit.DB import *

# Define input lists of geometry
t1 = IN[0] # List of Solid geometry
t2 = IN[1] # List of geometry (point, line, or solid)

# Initialize an empty list to store the results
t3 = []

# Loop through each solid geometry in t1
for i in range(len(t1)):
    # Initialize a sublist for each solid geometry
    sublist = []
    # Loop through each geometry in t2
    for j in range(len(t2)):
        # Check if the solid geometry intersects with the current geometry in t2
        result = t1[i].DoesIntersect(t2[j])
        # If the intersection is found, append the current geometry in t2 to the sublist
        if result:
            sublist.append(t2[j])
    # Append the sublist to the main list of results
    t3.append(sublist)

# Output the list of lists
OUT = t3

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 11, 2023, 11:57am UTC](https://forum.dynamobim.com/t/how-to-run-task-of-geometry-doesintersect-with-python-code-in-dynamo/88400/2 "2023-04-11T11:57:54Z")

</div>

One thing which can help here…

Currently you are running N_M tests, which can be significant from a processing time perspective.and since your net results are a list of objects from the second list which intersect an object in the first list, you really just want to know if the object in list 2 touches any object in list 1. Ideally you would just run just one test. Assuming you have a solid for the objects in list one, try unioning them into a single solid with a Solid.ByUnion node, and run the intersect test once for each object in list 2, reducing the test count to 1_M which should cut memory consumption significantly.
