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
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);
}
}
}
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
## 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)
## 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
Thank you @Organon and @c.poupin for your help in understanding this subject about
IntersectionResultArray. The result is working amazingly!
Another step complete!
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