Get grids intersection Points with XYZ coordinates

Hello everyone.
I’m in the process o writing a Script intended to generate grids layouts with families at grids intersections automatically. All in Python language.
I’ve been already able to create grids through the API, but now I’m stucked because I can´t get the intersection points. The Intersect Method applied to grid curves only returns the SetComparisonResult “Overlap” Enumeration.
Does anyone have an idea on how to get the XYZ points of intersection?
This is the Python code I’m working with.

import sys
import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
from Autodesk.Revit.Creation import ItemFactoryBase

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

axis = UnwrapElement(IN[0])
axis_x =  axis[0]
axis_y = axis[1]
level = UnwrapElement(IN[1])

##Get curves
curves_x = [x.Curve for x in axis_x]
curves_Y = [y.Curve for y in axis_y]

##Curves Intersection
intx = []
for x in curves_x:
	for y in curves_Y:
		int = x.Intersect(y)
		intx.append(int)

OUT = intx

And the result:

Thanks!

1 Like

@DavidMena

Hi,

You can try this method:
Curve Class (revitapidocs.com)

Regards,

1 Like

@Organon How do you implement that method? I´m trying this:
int = x.Intersect(y, IntersectionResultArray)
But I get this error:

TypeError: expected StrongBox[IntersectionResultArray], got type

@DavidMena

I wrote this code in C# some time ago, but you can use it to understand the concept.

// Get intersection points.
IntersectionResultArray ira = new IntersectionResultArray(); 

List<XYZ> points = new List<XYZ>(); 
foreach (PlanarFace face in faces)
{
    SetComparisonResult result = face.Intersect(ncurve, out ira);
    if (result == SetComparisonResult.Overlap)
    {
        foreach (IntersectionResult ir in ira)
        {
            XYZ pt = ir.XYZPoint;
            points.Add(pt);
        }
    }
}
1 Like

@DavidMena

Check this post:
Translating to Python - Developers - Dynamo (dynamobim.com)

1 Like

Thank you @Organon. But the problem is that I’m not just anylizing 2 lines, I’m analyzing a set o lines in X and a set of lines in Y (grids intersection). And although I’m getting better in understanding the logic of intersections I still cannot understand why it returns me a list of the same number :open_mouth: :open_mouth:

## curves
curves_x = [x.Curve for x in axis_x]
curves_Y = [y.Curve for y in axis_y]

##Intersections
results = clr.Reference[IntersectionResultArray]()
intx = []
items = []
points = []
for x in curves_x:
	for y in curves_Y:
		int = x.Intersect(y, results)
		intx.append(int)
for i in intx:
	if i != SetComparisonResult.Overlap:
		OUT = "No Overlaping"
	intersection = results.Item[0]
	items.append(intersection)
for item in items:
	point = item.XYZPoint
	points.append(point)

puntos

@DavidMena

Try this:

## Inputs
axis_x = UnwrapElement(IN[0])
axis_y = UnwrapElement(IN[1])

## Curves
curves_x = [x.Curve for x in axis_x]
curves_Y = [y.Curve for y in axis_y]

## Intersections
results = clr.Reference[IntersectionResultArray]()

points = []
for x in curves_x:
	for y in curves_Y:	
		int = x.Intersect(y, results)
		if int != SetComparisonResult.Overlap:
		     OUT = "No Overlaping"
		else:
		    point = results.Item[0].XYZPoint
	        points.append(point)

OUT = points
2 Likes

Hello,
for Ironpython here is the good syntax according to the doc for refs/out parameters (incoming argument value is accessed by reading the Value property)
https://ironpython.net/documentation/dotnet/dotnet.html#methods-with-ref-or-out-parameters

4 Likes

Thank you @Organon and @c.poupin for your help in understanding this subject about
IntersectionResultArray. The result is working amazingly!
Another step complete!

2 Likes

Hi, can you share your code?

Am placing ceiling hangers on the ceiling grid intersection and wondering if i can use your method?

Sure!
This is when you have a set of grids already created:

doc = DocumentManager.Instance.CurrentDBDocument

ejes = UnwrapElement(IN[0])
ejes_x =  ejes[0]
ejes_y = ejes[1]
level = UnwrapElement(IN[1])

##Get curves
curves_x = [x.Curve for x in ejes_x]
curves_Y = [y.Curve for y in ejes_y]

##Curves intersections
results = clr.Reference[IntersectionResultArray]()

points = []
for x in curves_x:
	for y in curves_Y:
		int = x.Intersect(y, results)
		if int != SetComparisonResult.Overlap:
			OUT = "No Overlaping"
		else:
			point = results.Item[0].XYZPoint
			points.append(point)

props = [p.GetType() for p in points]

##FamilySymbol
FamSym = FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_StructuralColumns).ToElements()

zapatas = FilteredElementCollector(doc).OfClass(FamilySymbol).OfCategory(BuiltInCategory.OST_StructuralFoundation).ToElements()

###Family Creation between axis###
TransactionManager.Instance.EnsureInTransaction(doc)

for p in points:
	col = doc.Create.NewFamilyInstance(p, FamSym[0], level, StructuralType.Column)
	zap = doc.Create.NewFamilyInstance(p, zapatas[0], level, StructuralType.Column)

TransactionManager.Instance.TransactionTaskDone()

Hi @DavidMena, do you know if this method works in Dynamo/CPython3 for Revit 2023? I cannot seem to get a result on checking the SetComparisonResult value (seen here as SetComparisonResult.Overlap) where I now seem to be getting returned an integer value. The same seems to be happening with the lesser Line1.Intersect(Line2) i.e. a simple integer returned