Skip to content

Commit 8e1b5e8

Browse files
committed
Updated Convert C# to python code sample
1 parent 344ad4c commit 8e1b5e8

File tree

1 file changed

+82
-7
lines changed

1 file changed

+82
-7
lines changed
Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""
2-
Example of a XYZ Constructor using Python. For more information see:
3-
revitapidocs.com/2016/fcb91231-2665-54b9-11d6-7ebcb7f235e2.htm
2+
Examples of C# code, followed by its Python Equivalent
43
54
TESTED REVIT API: -
65
@@ -11,20 +10,96 @@
1110
License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md
1211
"""
1312

13+
# Blog Post about this same topic
14+
# http://thebar.cc/converting-revit-api-c-code-to-python/
15+
16+
""""
17+
Class XYZ
18+
revitapidocs.com/2016/fcb91231-2665-54b9-11d6-7ebcb7f235e2.htm
19+
20+
public XYZ(double x, double y, double z)
21+
22+
Usage:
23+
>>> XYZ point = new XYZ(0, 0, 0);
24+
"""
25+
26+
from Autodesk.Revit.DB import XYZ
27+
28+
point = XYZ(10, 10, 10)
29+
print(point.X)
30+
# 10
1431

1532
""""
1633
CSharp Class Constructors
34+
revitapidocs.com/2016/fcb91231-2665-54b9-11d6-7ebcb7f235e2.htm
1735
1836
public XYZ(double x, double y, double z)
1937
2038
Usage:
21-
XYZ point = new XYZ(0, 0, 0);
39+
>>> XYZ point = new XYZ(0, 0, 0);
2240
"""
2341

24-
# Python Equivalent
2542
from Autodesk.Revit.DB import XYZ
2643

2744
point = XYZ(10, 10, 10)
28-
#############################
29-
>>> print(point.X)
30-
# >>> 10
45+
print(point.X)
46+
# 10
47+
48+
""""
49+
FilteredElementCollector Class
50+
http://www.revitapidocs.com/2018/263cf06b-98be-6f91-c4da-fb47d01688f3.htm
51+
52+
public FilteredElementCollector(
53+
Document document
54+
)
55+
56+
Usage:
57+
>>> FilteredElementCollector collector = new FilteredElementCollector(doc);
58+
>>> walls = collector.OfClass(Wall).ToElements()
59+
"""
60+
from Autodesk.Revit.DB import FilteredElementCollector, Wall
61+
62+
collector = FilteredElementCollector(doc)
63+
walls = collector.ToElements()
64+
65+
66+
""""
67+
Line Intersect Method (Users Out/Ref Values)
68+
http://www.revitapidocs.com/2018/51961478-fb36-e00b-2d1b-7db27b0a09e6.htm
69+
70+
public SetComparisonResult Intersect(
71+
Curve curve,
72+
out IntersectionResultArray resultArray
73+
)
74+
75+
Usage:
76+
>>> IntersectionResultArray results;
77+
>>> SetComparisonResult result = line1.Intersect( line2, out results );
78+
>>> if( result != SetComparisonResult.Overlap ) {
79+
... throw new InvalidOperationException("Input lines did not intersect." );
80+
... };
81+
>>> if( results == null || results.Size != 1 ) {
82+
... throw new InvalidOperationException("Could not extract line intersection point." );
83+
... }
84+
>>> IntersectionResult iResult
85+
= results.get_Item( 0 );
86+
87+
"""
88+
import clr
89+
from Autodesk.Revit.DB import SetComparisonResult, IntersectionResultArray
90+
from Autodesk.Revit.Exceptions import InvalidOperationException
91+
92+
line1 = Line.CreateBound(XYZ(0,0,0), XYZ(10,0,0))
93+
line2 = Line.CreateBound(XYZ(5,-5,0), XYZ(5,5,0))
94+
95+
results = clr.Reference[IntersectionResultArray]()
96+
result = line1.Intersect(line2, results)
97+
98+
if result != SetComparisonResult.Overlap:
99+
print('No Intesection')
100+
101+
if results is None or results.Size != 1:
102+
raise InvalidOperationException("Could not extract line intersection point." )
103+
104+
intersection = results.Item[0]
105+
xyz_point = intersection.XYZPoint

0 commit comments

Comments
 (0)