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!

@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

3 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