-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization_curve_script.py
More file actions
135 lines (99 loc) · 3.52 KB
/
Copy pathvisualization_curve_script.py
File metadata and controls
135 lines (99 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# /// script
# dependencies = []
# ///
"""
Test Curve Visualization
Demonstrates curve and edge visualization in 3D view.
Similar to RevitDevTool.DotnetDemo/CurveVisualization.cs
"""
from Autodesk.Revit import UI, DB
from Autodesk.Revit.UI.Selection import ObjectType
def test_single_edge(uidoc: UI.UIDocument):
"""Pick an edge and visualize it"""
try:
print("Select an edge...")
ref = uidoc.Selection.PickObject(ObjectType.Edge, "Select an edge")
elem = uidoc.Document.GetElement(ref)
edge = elem.GetGeometryObjectFromReference(ref)
if edge:
print(f"Selected edge: {edge.GetType().Name}")
print(edge) # Visualize in 3D view
else:
print("ERROR: Could not get edge geometry")
except Exception as e:
print(f"ERROR: {e}")
def test_multiple_edges(uidoc: UI.UIDocument):
"""Pick multiple edges and visualize them"""
try:
print("Select multiple edges (ESC when done)...")
refs = uidoc.Selection.PickObjects(ObjectType.Edge, "Select edges")
if len(refs) == 0:
print("WARNING: No edges selected")
return
print(f"Selected {len(refs)} edges")
# Visualize each edge
for i, ref in enumerate(refs):
elem = uidoc.Document.GetElement(ref)
edge = elem.GetGeometryObjectFromReference(ref)
if edge:
print(f"Edge {i + 1}: {edge.GetType().Name}")
print(edge)
except Exception as e:
print(f"ERROR: {e}")
def test_wall_curves(uidoc: UI.UIDocument):
"""Visualize all wall location curves"""
try:
print("Collecting wall curves...")
walls = DB.FilteredElementCollector(uidoc.Document).OfClass(DB.Wall).ToElements()
count = 0
for wall in walls:
if wall.Location and hasattr(wall.Location, "Curve"):
curve = wall.Location.Curve
print(curve) # Visualize in 3D view
count += 1
print(f"Visualized {count} wall curves")
except Exception as e:
print(f"ERROR: {e}")
def test_generated_lines():
"""Generate and visualize lines"""
try:
print("Generating lines...")
# Create a square
points = [
DB.XYZ(0, 0, 0),
DB.XYZ(10, 0, 0),
DB.XYZ(10, 10, 0),
DB.XYZ(0, 10, 0),
DB.XYZ(0, 0, 0), # Close the square
]
for i in range(len(points) - 1):
line = DB.Line.CreateBound(points[i], points[i + 1])
print(f"Line {i + 1}: {points[i]} -> {points[i + 1]}")
print(line) # Visualize in 3D view
print(f"Generated {len(points) - 1} lines")
except Exception as e:
print(f"ERROR: {e}")
def test_arc():
"""Generate and visualize an arc"""
try:
print("Generating arc...")
start = DB.XYZ(0, 0, 0)
end = DB.XYZ(10, 0, 0)
mid = DB.XYZ(5, 5, 0)
arc = DB.Arc.Create(start, end, mid)
print(f"Arc: radius={arc.Radius:.2f}, length={arc.Length:.2f}")
print(arc) # Visualize in 3D view
except Exception as e:
print(f"ERROR: {e}")
def main():
print("=== Curve Visualization Test ===")
print()
uidoc: UI.UIDocument = __revit__.ActiveUIDocument # type: ignore # noqa: F821
# Uncomment the test you want to run:
# test_single_edge(uidoc)
# test_multiple_edges(uidoc)
# test_wall_curves(uidoc)
test_generated_lines()
# test_arc()
if __name__ == "__main__":
main()