-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrimesh_script.py
More file actions
67 lines (51 loc) · 1.88 KB
/
Copy pathtrimesh_script.py
File metadata and controls
67 lines (51 loc) · 1.88 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
# /// script
# dependencies = [
# "shapely==2.1.2",
# "trimesh==4.11.2",
# "pydantic==2.12.5",
# ]
# ///
from Autodesk.Revit import DB
import trimesh
def create_simple_box():
cube = trimesh.creation.box(extents=(2, 2, 2))
edges = cube.edges_unique
vertices = cube.vertices
bbox = DB.BoundingBoxXYZ()
bbox.Min = DB.XYZ(vertices.min(axis=0)[0], vertices.min(axis=0)[1], vertices.min(axis=0)[2])
bbox.Max = DB.XYZ(vertices.max(axis=0)[0], vertices.max(axis=0)[1], vertices.max(axis=0)[2])
print(bbox)
lines = []
# 2. Convert edges to Revit Lines
for edge in edges:
start_vertex = vertices[edge[0]]
end_vertex = vertices[edge[1]]
start_point = DB.XYZ(start_vertex[0], start_vertex[1], start_vertex[2])
end_point = DB.XYZ(end_vertex[0], end_vertex[1], end_vertex[2])
try:
line = DB.Line.CreateBound(start_point, end_point)
lines.append(line)
except Exception as e:
print(f"Error creating line: {e}")
# print(lines)
print(f"Created {len(lines)} lines in Revit from Trimesh cube edges.")
def create_complex_shape():
sphere = trimesh.creation.icosphere(subdivisions=2, radius=1.0)
edges = sphere.edges_unique
vertices = sphere.vertices
lines = []
for edge in edges:
start_vertex = vertices[edge[0]]
end_vertex = vertices[edge[1]]
start_point = DB.XYZ(start_vertex[0], start_vertex[1], start_vertex[2])
end_point = DB.XYZ(end_vertex[0], end_vertex[1], end_vertex[2])
try:
line = DB.Line.CreateBound(start_point, end_point)
lines.append(line)
except Exception as e:
print(f"Error creating line: {e}")
print(lines)
print(f"Created {len(lines)} lines in Revit from Trimesh sphere edges.")
if __name__ == "__main__":
create_simple_box()
create_complex_shape()