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

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.

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

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

One thing which can help here…

Currently you are running NM 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 1M which should cut memory consumption significantly.

1 Like