|
1 | 1 | """ |
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 |
4 | 3 |
|
5 | 4 | TESTED REVIT API: - |
6 | 5 |
|
|
11 | 10 | License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md |
12 | 11 | """ |
13 | 12 |
|
| 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 |
14 | 31 |
|
15 | 32 | """" |
16 | 33 | CSharp Class Constructors |
| 34 | +revitapidocs.com/2016/fcb91231-2665-54b9-11d6-7ebcb7f235e2.htm |
17 | 35 |
|
18 | 36 | public XYZ(double x, double y, double z) |
19 | 37 |
|
20 | 38 | Usage: |
21 | | -XYZ point = new XYZ(0, 0, 0); |
| 39 | +>>> XYZ point = new XYZ(0, 0, 0); |
22 | 40 | """ |
23 | 41 |
|
24 | | -# Python Equivalent |
25 | 42 | from Autodesk.Revit.DB import XYZ |
26 | 43 |
|
27 | 44 | 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