Skip to content

Commit f0f725f

Browse files
WIP rhino and examples.
1 parent 6b030e2 commit f0f725f

8 files changed

+424
-26
lines changed

docs/examples/binding_closed_mesh_from_polylines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from compas_viewer import Viewer
1616

1717
viewer = Viewer()
18-
viewer.add(mesh, show_faces=True, show_edges=True, show_points=False)
18+
viewer.scene.add(mesh, show_faces=True, show_edges=True, show_points=False)
1919
viewer.show()
2020

2121
except ImportError:

docs/examples/binding_get_connection_zones.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
]
2828

2929
# generate joints
30-
output_polylines, output_types = get_connection_zones(
30+
polylines_lists, output_types, new_polyline_lists = get_connection_zones(
3131
data_sets_plates.annen_small_polylines(),
3232
data_sets_plates.annen_small_edge_directions(),
3333
data_sets_plates.annen_small_edge_joints(),
@@ -48,7 +48,7 @@
4848
scale = 1e-3
4949
scale_transform = Scale.from_factors([scale, scale, scale])
5050
viewer = Viewer(show_grid=False)
51-
for polylines in output_polylines:
51+
for polylines in polylines_lists:
5252
for polyline in polylines:
5353
polyline.transform(scale_transform)
5454
viewer.scene.add(Polyline(polyline), show_points=False)

docs/examples/binding_get_connection_zones_beams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
]
5959

6060
# generate joints
61-
output_polylines, output_types = get_connection_zones(
61+
polylines_lists, output_types, new_polyline_lists = get_connection_zones(
6262
polylines,
6363
[],
6464
[],
@@ -79,7 +79,7 @@
7979
scale = 1e-1
8080
scale_transform = Scale.from_factors([scale, scale, scale])
8181
viewer = Viewer(show_grid=False)
82-
for polylines in output_polylines:
82+
for polylines in polylines_lists:
8383
for polyline in polylines:
8484
polyline.transform(scale_transform)
8585
viewer.scene.add(Polyline(polyline), show_points=False)

src/rhino/plugin/commands/w_dataset_beam_volume.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ def my_callback(
228228
):
229229

230230
input_polyline_axes = name_value_type["polyline_axes"][0]
231-
232231
input_radii = name_value_type["polylines_segment_radii"][0]
233232
input_polylines_segment_direction = name_value_type["polylines_segment_direction"][0]
233+
234+
234235
input_allowed_types_per_polyline = name_value_type["allowed_types_per_polyline"][0]
235236
input_min_distance = name_value_type["min_distance"][0]
236237
input_volume_length = name_value_type["volume_length"][0]
@@ -258,6 +259,13 @@ def my_callback(
258259
for j in range(input_polyline_axes[i].SegmentCount):
259260
input_polyline_segment_direction.append(Vector3d(0, 1, 0))
260261
input_polylines_segment_direction.append(input_polyline_segment_direction)
262+
263+
264+
print("___________________")
265+
print(input_polyline_axes)
266+
print(input_polylines_segment_radii)
267+
print(input_polylines_segment_direction)
268+
print("___________________")
261269

262270
index_polylines = int2()
263271
index_polylines_segment = int2()
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#! python3
2+
# venv: timber_connections
3+
import Rhino
4+
import Rhino.Input.Custom as ric
5+
from wood_rui import wood_rui_globals, add_joinery, add_polylines, generalized_input_method, Element
6+
from wood_nano import get_connection_zones as wood_nano_get_connection_zones
7+
from wood_nano import cut_type2 as wood_nano_cut_type2
8+
from wood_nano import point3 as wood_nano_point3
9+
from wood_nano.conversions_python import to_int2
10+
from wood_nano.conversions_python import to_int1
11+
from wood_nano.conversions_python import to_double1
12+
from wood_nano.conversions_python import from_cut_type2
13+
from compas_wood.conversions_rhino import to_point2
14+
from compas_wood.conversions_rhino import to_vector2
15+
from compas_wood.conversions_rhino import from_point3
16+
from compas_wood.binding import wood_globals
17+
from typing import List
18+
19+
######################################################################
20+
# Select Elements:
21+
# a) get indices and neighbors since selection is made in a random order.
22+
# b) store joints in elements.
23+
# c) create lofts and cylinders from the polyline geometry and store them in features.
24+
# d) repeat the process for side-to-end, end-to-end, and cross connections as examples.
25+
######################################################################
26+
27+
28+
29+
def solver(dataset_name: str) -> None:
30+
"""
31+
Run the solver with the selected dataset, using properties from global parameters.
32+
33+
Args:
34+
dataset_name (str): Name of the dataset to solve.
35+
"""
36+
37+
w_output_plines: wood_nano_point3 = wood_nano_point3()
38+
w_output_types: wood_nano_cut_type2 = wood_nano_cut_type2()
39+
40+
adjacency_flat_list: List[int] = []
41+
adjacency_data: List[List[int]] = (
42+
wood_rui_globals[dataset_name]["adjacency"]
43+
if wood_rui_globals[dataset_name]["adjacency"]
44+
else wood_rui_globals.adjacency
45+
)
46+
47+
for sublist in adjacency_data:
48+
for item in sublist:
49+
adjacency_flat_list.append(item)
50+
51+
# print(wood_rui_globals[dataset_name]["joints_per_face"])
52+
# print(wood_rui_globals[dataset_name]["three_valence"])
53+
54+
# select the three valence depending on the dataset dictionary property or the global property
55+
three_valence = (
56+
wood_rui_globals[dataset_name]["three_valence"]
57+
if wood_rui_globals[dataset_name]["three_valence"]
58+
else wood_rui_globals.three_valence
59+
)
60+
three_valence = (
61+
wood_rui_globals[dataset_name]["three_valence"]
62+
if wood_rui_globals[dataset_name]["three_valence"]
63+
else wood_rui_globals.three_valence
64+
)
65+
66+
print(wood_rui_globals[dataset_name]["polylines"])
67+
68+
wood_nano_get_connection_zones(
69+
to_point2(wood_rui_globals[dataset_name]["polylines"]),
70+
to_vector2(wood_rui_globals[dataset_name]["insertion_vectors"]),
71+
to_int2(
72+
wood_rui_globals[dataset_name]["joints_per_face"]
73+
), # to_int2(wood_rui_globals[dataset_name]["joints_dots"]),
74+
to_int2(
75+
three_valence
76+
), # to_int2(wood_rui_globals[dataset_name]["three_valence_element_indices_and_instruction"]),
77+
to_int1(adjacency_flat_list),
78+
to_double1(wood_globals.joints_parameters_and_types),
79+
int(wood_rui_globals.search_type),
80+
to_double1(wood_rui_globals.scale),
81+
int(wood_globals.output_geometry_type),
82+
w_output_plines,
83+
w_output_types,
84+
to_double1(wood_rui_globals.joint_volume_extension),
85+
)
86+
87+
add_joinery(from_point3(w_output_plines), dataset_name)
88+
print(wood_rui_globals[dataset_name]["joinery"])
89+
90+
# Add joint types if the output type is 3
91+
is_output_type_3: bool = int(wood_globals.output_geometry_type) == 3
92+
93+
if is_output_type_3:
94+
joint_types: List[List[int]] = from_cut_type2(w_output_types)
95+
96+
# Before assigning the joint type, be sure to have correct number of valid joinery polylines
97+
number_added_polylines: int = 0
98+
for i in range(len(wood_rui_globals[dataset_name]["joinery"])):
99+
number_added_polylines += len(wood_rui_globals[dataset_name]["joinery"][i])
100+
101+
if number_added_polylines == len(wood_rui_globals[dataset_name]["joinery_guid"]):
102+
counter: int = 0
103+
for i, output_type in enumerate(w_output_types):
104+
for j in range(len(wood_rui_globals[dataset_name]["joinery"][i])):
105+
guid: str = wood_rui_globals[dataset_name]["joinery_guid"][counter]
106+
rhino_object: Rhino.DocObjects.RhinoObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid)
107+
108+
if is_output_type_3:
109+
joint_type: int = joint_types[i][int(j * 0.5)]
110+
rhino_object.Attributes.SetUserString("joint_type", str(joint_type))
111+
112+
rhino_object.Attributes.SetUserString("element_id", str(i))
113+
rhino_object.Attributes.SetUserString("face_id", str(j))
114+
counter += 1
115+
else:
116+
print("Number of added joinery is not equal to number joinery_guids. There are invalid polylines.")
117+
118+
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw() # 0 ms
119+
120+
121+
def my_callback(
122+
name_value_type,
123+
dataset_name,
124+
):
125+
126+
print(name_value_type)
127+
input_elements = name_value_type["elements"]
128+
129+
if len(input_elements) == 0:
130+
print("Attention: no elements selected.")
131+
return
132+
133+
if __name__ == "__main__":
134+
135+
# Define the input dictionary based on your initial dataset
136+
input_dict = {
137+
"elements" : ([], List[Element]),
138+
}
139+
140+
# Call the generalized input method with the dataset name and input dictionary
141+
dataset_name = "beams"
142+
wood_rui_globals.init_data(dataset_name)
143+
generalized_input_method(dataset_name, input_dict, my_callback)
144+
145+
146+
# if __name__ == "__main__":
147+
# dataset_name: str = command_line_input()
148+
# if dataset_name:
149+
# solver(dataset_name)

0 commit comments

Comments
 (0)