-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathex090_wall_courses.py
50 lines (33 loc) · 1.16 KB
/
ex090_wall_courses.py
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
"""Identify the courses of a assembly assembly.
Steps
-----
1. Load an assembly from a JSON file.
2. Identify the course rows
3. serialise to JSON
Notes
-----
This will only work as expected on *wall* assemblies that are properly supported.
Exercise
--------
Check if all blocks of bottom course are supported.
"""
import os
from compas_assembly.datastructures import Assembly
from compas_assembly.datastructures import assembly_courses
HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '../data')
PATH_FROM = os.path.join(DATA, '08_wall_interfaces.json')
PATH_TO = os.path.join(DATA, '090_wall_courses.json')
# load an assembly from JSON
assembly = Assembly.from_json(PATH_FROM)
# check if the assembly has supports
supports = list(assembly.vertices_where({'is_support': True}))
if not supports:
raise Exception("The assembly has no supports.")
# identify the courses
courses = assembly_courses(assembly)
# assign course id's to the corresponding blocks
for i, course in enumerate(courses):
assembly.set_vertices_attribute('course', i, keys=course)
# serialise the result
assembly.to_json(PATH_TO)