Skip to content

Commit f20d9c2

Browse files
committed
Added GetLineIntersection
1 parent 5e54428 commit f20d9c2

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Get Line Intersection
3+
Get's intersection of 2 lines
4+
5+
TESTED REVIT API: 2017
6+
7+
Author: Gui Talarico | github.com/gtalarico
8+
9+
This file is shared on www.revitapidocs.com
10+
For more information visit http://github.com/gtalarico/revitapidocs
11+
License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md
12+
"""
13+
14+
import clr
15+
from Autodesk.Revit.DB import Line, XYZ
16+
from Autodesk.Revit.DB import SetComparisonResult, IntersectionResultArray
17+
18+
def get_intersection(line1, line2):
19+
results = clr.Reference[IntersectionResultArray]()
20+
# See ironpython.net/documentation/dotnet for clr.Reference
21+
22+
result = line1.Intersect(line2, results)
23+
# http://www.revitapidocs.com/2018/51961478-fb36-e00b-2d1b-7db27b0a09e6.htm
24+
25+
if result != SetComparisonResult.Overlap:
26+
print('No Intesection')
27+
28+
intersection = results.Item[0]
29+
return intersection.XYZPoint
30+
31+
32+
line1 = Line.CreateBound(XYZ(0,0,0), XYZ(10,0,0))
33+
line2 = Line.CreateBound(XYZ(5,-5,0), XYZ(5,5,0))
34+
point = get_intersection(line1, line2)
35+
print(point)
36+
# <Autodesk.Revit.DB.XYZ object at 0x00000000000001BA [(5.000000000, 0.000000000, 0.000000000)]>
37+
38+
"""
39+
From this discussion:
40+
https://forum.dynamobim.com/t/translating-to-python/13481
41+
42+
C# Equivalent
43+
44+
private XYZ GetIntersection(
45+
Line line1,
46+
Line line2 )
47+
{
48+
IntersectionResultArray results;
49+
50+
SetComparisonResult result
51+
= line1.Intersect( line2, out results );
52+
53+
if( result != SetComparisonResult.Overlap )
54+
throw new InvalidOperationException(
55+
"Input lines did not intersect." );
56+
57+
if( results == null || results.Size != 1 )
58+
throw new InvalidOperationException(
59+
"Could not extract line intersection point." );
60+
61+
IntersectionResult iResult
62+
= results.get_Item( 0 );
63+
64+
return iResult.XYZPoint;
65+
}
66+
"""

0 commit comments

Comments
 (0)