How would I change this into a Python script?
private XYZ GetIntersection(
Line line1,
Line line2 )
{
IntersectionResultArray results;
SetComparisonResult result
= line1.Intersect( line2, out results );
if( result != SetComparisonResult.Overlap )
throw new InvalidOperationException(
"Input lines did not intersect." );
if( results == null || results.Size != 1 )
throw new InvalidOperationException(
"Could not extract line intersection point." );
IntersectionResult iResult
= results.get_Item( 0 );
return iResult.XYZPoint;
}
I can sometimes work out the logic but this one has me scratching my head.
What was the code written in before?
yyi
July 27, 2017, 3:30am
3
Isn’t this a snippet from Revit SDK sample code CreateTruss in C#? Should look for a package of that.
It is. I pulled it from Jeremy’s blog but he said it was from the SDK. Would there be a Python script there as well?
yyi
July 27, 2017, 4:35am
5
SDK samples are usually in C#. A few of them have VB equivalents. As far as I know no official python scripts.
Yeah, that’s what I thought, hence the question.
import clr
from Autodesk.Revit.DB import Line, XYZ
from Autodesk.Revit.DB import SetComparisonResult, IntersectionResultArray
def get_intersection(line1, line2):
results = clr.Reference[IntersectionResultArray]()
# See ironpython.net/documentation/dotnet for clr.Reference
result = line1.Intersect(line2, results)
# http://www.revitapidocs.com/2018/51961478-fb36-e00b-2d1b-7db27b0a09e6.htm
if result != SetComparisonResult.Overlap:
print('No Intesection')
intersection = results.Item[0]
return intersection.XYZPoint
line1 = Line.CreateBound(XYZ(0,0,0), XYZ(10,0,0))
line2 = Line.CreateBound(XYZ(5,-5,0), XYZ(5,5,0))
point = get_intersection(line1, line2)
print(point)
# <Autodesk.Revit.DB.XYZ object at 0x00000000000001BA [(5.000000000, 0.000000000, 0.000000000)]>
6 Likes
Hi @Gui_Talarico 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.