Skip to content

Commit ca1eed0

Browse files
committed
added circuit board example
1 parent b18d176 commit ca1eed0

6 files changed

+91
-34
lines changed
Loading
Loading
Loading

docs/examples_1.rst

+45-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ Most of the examples show the builder and algebra modes.
4040
:link-type: ref
4141

4242

43-
.. grid-item-card:: Canadian Flag blowing in the wind |Builder| |Algebra|
43+
.. grid-item-card:: Circuit Board With Holes |Builder| |Algebra|
4444
:img-top: assets/examples/thumbnail_canadian_flag_01.png
4545
:link: examples-canadian_flag
4646
:link-type: ref
4747

48+
49+
.. grid-item-card:: Canadian Flag Blowing in The Wind |Builder| |Algebra|
50+
:img-top: assets/examples/thumbnail_circuit_board_01.png
51+
:link: examples-circuit_board
52+
:link-type: ref
53+
4854
.. NOTE 01: insert new example thumbnails above this line
4955
5056
.. TODO: Copy this block to add the example thumbnails here
@@ -165,8 +171,8 @@ The builder mode example also generates the SVG file `logo.svg`.
165171

166172
.. _examples-canadian_flag:
167173

168-
Canadian Flag blowing in the wind
169-
--------------------------------
174+
Canadian Flag Blowing in The Wind
175+
----------------------------------
170176
.. image:: assets/examples/example_canadian_flag_01.png
171177
:align: center
172178

@@ -199,6 +205,42 @@ This example also demonstrates building complex lines that snap to existing feat
199205
:end-before: [End]
200206

201207

208+
.. _examples-circuit_board:
209+
210+
211+
Circuit Board With Holes
212+
------------------------
213+
.. image:: assets/examples/example_circuit_board_01.png
214+
:align: center
215+
216+
217+
218+
This example demonstrates placing holes around a part.
219+
220+
- Builder mode uses `Locations` context to place the positions.
221+
- Algebra mode uses `product` and `range` to calculate the positions.
222+
223+
224+
225+
.. dropdown:: More Images
226+
227+
.. image:: assets/examples/example_circuit_board_02.png
228+
:align: center
229+
230+
231+
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
232+
233+
.. literalinclude:: ../examples/circuit_board.py
234+
:start-after: [Code]
235+
:end-before: [End]
236+
237+
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
238+
239+
.. literalinclude:: ../examples/circuit_board_algebra.py
240+
:start-after: [Code]
241+
:end-before: [End]
242+
243+
202244
.. NOTE 02: insert new example thumbnails above this line
203245
204246

examples/circuit_board.py

+31-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
"""
2-
3-
name: circuit_board.py
4-
by: Gumyr
5-
date: September 1st 2022
6-
7-
desc:
8-
2+
name: "circuit_board.py"
3+
title: "Circuit Board With Holes"
4+
authors: "Gumyr"
5+
license: "http://www.apache.org/licenses/LICENSE-2.0"
6+
created: "2022-09-01"
7+
modified: "2024-01-27"
8+
9+
description: |
910
This example demonstrates placing holes around a part.
10-
11-
license:
12-
13-
Copyright 2022 Gumyr
14-
15-
Licensed under the Apache License, Version 2.0 (the "License");
16-
you may not use this file except in compliance with the License.
17-
You may obtain a copy of the License at
18-
19-
http://www.apache.org/licenses/LICENSE-2.0
20-
21-
Unless required by applicable law or agreed to in writing, software
22-
distributed under the License is distributed on an "AS IS" BASIS,
23-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24-
See the License for the specific language governing permissions and
25-
limitations under the License.
11+
12+
- Builder mode uses `Locations` context to place the positions.
13+
- Algebra mode uses `product` and `range` to calculate the positions.
14+
15+
has_builder_mode: true
16+
has_algebra_mode: true
17+
image_files:
18+
- "example_circuit_board_01.png"
19+
- "example_circuit_board_02.png"
2620
"""
21+
22+
# [Imports]
2723
from build123d import *
24+
from ocp_vscode import *
2825

26+
# [Parameters]
27+
pcb_length = 70 * MM
28+
pcb_width = 30 * MM
29+
pcb_height = 3 * MM
30+
31+
# [Code]
2932
with BuildPart() as pcb:
3033
with BuildSketch():
31-
Rectangle(70, 30)
34+
Rectangle(pcb_length, pcb_width)
35+
3236
for i in range(65 // 5):
3337
x = i * 5 - 30
3438
with Locations((x, -15), (x, -10), (x, 10), (x, 15)):
@@ -39,7 +43,7 @@
3943
Circle(1, mode=Mode.SUBTRACT)
4044
with GridLocations(60, 20, 2, 2):
4145
Circle(2, mode=Mode.SUBTRACT)
42-
extrude(amount=3)
46+
extrude(amount=pcb_height)
4347

44-
if "show_object" in locals():
45-
show_object(pcb.part.wrapped)
48+
show_object(pcb.part.wrapped)
49+
# [End]

examples/circuit_board_algebra.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1+
"""
2+
for details see `circuit_board.py`
3+
"""
4+
# [Imports]
15
from itertools import product
26
from build123d import *
7+
from ocp_vscode import show
38

9+
# [Parameters]
10+
pcb_length = 70 * MM
11+
pcb_width = 30 * MM
12+
pcb_height = 3 * MM
13+
14+
# [Code]
415
x_coords = product(range(65 // 5), (-15, -10, 10, 15))
516
y_coords = product((30, 35), range(30 // 5 - 1))
617

7-
pcb = Rectangle(70, 30)
18+
pcb = Rectangle(pcb_length, pcb_width)
819
pcb -= [Pos(i * 5 - 30, y) * Circle(1) for i, y in x_coords]
920
pcb -= [Pos(x, i * 5 - 10) * Circle(1) for x, i in y_coords]
1021
pcb -= [loc * Circle(2) for loc in GridLocations(60, 20, 2, 2)]
1122

12-
pcb = extrude(pcb, 3)
23+
pcb = extrude(pcb, pcb_height)
1324

14-
if "show_object" in locals():
15-
show(pcb)
25+
show(pcb)
26+
# [End]

0 commit comments

Comments
 (0)