added circuit board example

This commit is contained in:
Andreas **Felix** Häberle 2024-01-27 19:51:09 +01:00
parent b18d176706
commit ca1eed0916
6 changed files with 90 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -40,11 +40,17 @@ Most of the examples show the builder and algebra modes.
:link-type: ref
.. grid-item-card:: Canadian Flag blowing in the wind |Builder| |Algebra|
.. grid-item-card:: Circuit Board With Holes |Builder| |Algebra|
:img-top: assets/examples/thumbnail_canadian_flag_01.png
:link: examples-canadian_flag
:link-type: ref
.. grid-item-card:: Canadian Flag Blowing in The Wind |Builder| |Algebra|
:img-top: assets/examples/thumbnail_circuit_board_01.png
:link: examples-circuit_board
:link-type: ref
.. NOTE 01: insert new example thumbnails above this line
.. 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`.
.. _examples-canadian_flag:
Canadian Flag blowing in the wind
--------------------------------
Canadian Flag Blowing in The Wind
----------------------------------
.. image:: assets/examples/example_canadian_flag_01.png
:align: center
@ -199,6 +205,42 @@ This example also demonstrates building complex lines that snap to existing feat
:end-before: [End]
.. _examples-circuit_board:
Circuit Board With Holes
------------------------
.. image:: assets/examples/example_circuit_board_01.png
:align: center
This example demonstrates placing holes around a part.
- Builder mode uses `Locations` context to place the positions.
- Algebra mode uses `product` and `range` to calculate the positions.
.. dropdown:: More Images
.. image:: assets/examples/example_circuit_board_02.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/circuit_board.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/circuit_board_algebra.py
:start-after: [Code]
:end-before: [End]
.. NOTE 02: insert new example thumbnails above this line

View file

@ -1,34 +1,38 @@
"""
name: "circuit_board.py"
title: "Circuit Board With Holes"
authors: "Gumyr"
license: "http://www.apache.org/licenses/LICENSE-2.0"
created: "2022-09-01"
modified: "2024-01-27"
name: circuit_board.py
by: Gumyr
date: September 1st 2022
desc:
description: |
This example demonstrates placing holes around a part.
- Builder mode uses `Locations` context to place the positions.
- Algebra mode uses `product` and `range` to calculate the positions.
license:
Copyright 2022 Gumyr
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
has_builder_mode: true
has_algebra_mode: true
image_files:
- "example_circuit_board_01.png"
- "example_circuit_board_02.png"
"""
from build123d import *
# [Imports]
from build123d import *
from ocp_vscode import *
# [Parameters]
pcb_length = 70 * MM
pcb_width = 30 * MM
pcb_height = 3 * MM
# [Code]
with BuildPart() as pcb:
with BuildSketch():
Rectangle(70, 30)
Rectangle(pcb_length, pcb_width)
for i in range(65 // 5):
x = i * 5 - 30
with Locations((x, -15), (x, -10), (x, 10), (x, 15)):
@ -39,7 +43,7 @@ with BuildPart() as pcb:
Circle(1, mode=Mode.SUBTRACT)
with GridLocations(60, 20, 2, 2):
Circle(2, mode=Mode.SUBTRACT)
extrude(amount=3)
extrude(amount=pcb_height)
if "show_object" in locals():
show_object(pcb.part.wrapped)
show_object(pcb.part.wrapped)
# [End]

View file

@ -1,15 +1,26 @@
"""
for details see `circuit_board.py`
"""
# [Imports]
from itertools import product
from build123d import *
from ocp_vscode import show
# [Parameters]
pcb_length = 70 * MM
pcb_width = 30 * MM
pcb_height = 3 * MM
# [Code]
x_coords = product(range(65 // 5), (-15, -10, 10, 15))
y_coords = product((30, 35), range(30 // 5 - 1))
pcb = Rectangle(70, 30)
pcb = Rectangle(pcb_length, pcb_width)
pcb -= [Pos(i * 5 - 30, y) * Circle(1) for i, y in x_coords]
pcb -= [Pos(x, i * 5 - 10) * Circle(1) for x, i in y_coords]
pcb -= [loc * Circle(2) for loc in GridLocations(60, 20, 2, 2)]
pcb = extrude(pcb, 3)
pcb = extrude(pcb, pcb_height)
if "show_object" in locals():
show(pcb)
show(pcb)
# [End]