Updated Examples

This commit is contained in:
gumyr 2024-02-29 11:34:40 -05:00
parent 78a73a9963
commit f43dac38e2
56 changed files with 677 additions and 574 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

View file

@ -19,51 +19,85 @@ Most of the examples show the builder and algebra modes.
.. grid:: 3
.. grid-item-card:: Low Poly Benchy |Builder|
.. grid-item-card:: Benchy |Builder|
:img-top: assets/examples/thumbnail_benchy_01.png
:link: examples-benchy
:link-type: ref
.. grid-item-card:: Boxes on Faces |Builder| |Algebra|
:img-top: assets/examples/thumbnail_boxes_on_faces_01.png
:link: examples-boxes_on_faces
:link-type: ref
.. grid-item-card:: build123d customizable logo |Builder| |Algebra|
:img-top: assets/examples/thumbnail_build123d_customizable_logo_01.png
:link: examples-build123d_customizable_logo
:link-type: ref
.. grid-item-card:: Former build123d Logo |Builder| |Algebra|
:img-top: assets/examples/thumbnail_build123d_logo_01.png
:link: examples-build123d_logo
:link-type: ref
.. grid-item-card:: Circuit Board With Holes |Builder| |Algebra|
:img-top: assets/examples/thumbnail_circuit_board_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_canadian_flag_01.png
:img-top: assets/examples/example_canadian_flag_01.png
:link: examples-circuit_board
:link-type: ref
.. grid-item-card:: Clock Face |Builder| |Algebra|
:img-top: assets/examples/clock_face.png
:link: clock_face
:link-type: ref
.. grid-item-card:: Handle |Builder| |Algebra|
:img-top: assets/examples/handle.png
:link: handle
:link-type: ref
.. grid-item-card:: Heat Exchanger |Builder| |Algebra|
:img-top: assets/examples/heat_exchanger.png
:link: heat_exchanger
:link-type: ref
.. grid-item-card:: Key Cap |Builder| |Algebra|
:img-top: assets/examples/key_cap.png
:link: key_cap
:link-type: ref
.. grid-item-card:: (former) build123d Logo |Builder| |Algebra|
:img-top: assets/examples/thumbnail_build123d_logo_01.png
:link: examples-build123d_logo
:link-type: ref
.. grid-item-card:: Maker Coin |Builder|
:img-top: assets/examples/maker_coin.png
:link: maker_coin
:link-type: ref
.. grid-item-card:: Multi-Sketch Loft |Builder| |Algebra|
:img-top: assets/examples/loft.png
:link: multi_sketch_loft
:link-type: ref
.. grid-item-card:: Peg Board J Hook |Builder| |Algebra|
:img-top: assets/examples/peg_board_hook.png
:link: peg_board_hook
:link-type: ref
.. grid-item-card:: Platonic Solids |Algebra|
:img-top: assets/examples/platonic_solids.png
:link: platonic_solids
:link-type: ref
.. grid-item-card:: Playing Cards |Builder|
:img-top: assets/examples/playing_cards.png
:link: playing_cards
:link-type: ref
.. grid-item-card:: Stud Wall |Algebra|
:img-top: assets/examples/stud_wall.png
:link: stud_wall
:link-type: ref
.. grid-item-card:: Tea Cup |Builder| |Algebra|
:img-top: assets/examples/tea_cup.png
:link: tea_cup
:link-type: ref
.. grid-item-card:: Vase |Builder| |Algebra|
:img-top: assets/examples/vase.png
:link: vase
:link-type: ref
.. NOTE 01: insert new example thumbnails above this line
@ -79,8 +113,8 @@ Most of the examples show the builder and algebra modes.
.. _examples-benchy:
Low Poly Benchy
--------------------------------
Benchy
------
.. image:: assets/examples/example_benchy_01.png
:align: center
@ -112,51 +146,6 @@ modify it by replacing chimney with a BREP version.
.. ----------------------------------------------------------------------------------------------
.. _examples-boxes_on_faces:
Boxes on Faces
--------------------------------
.. image:: assets/examples/example_boxes_on_faces_01.png
:align: center
Create elements on every face of a box.
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/boxes_on_faces.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/boxes_on_faces_algebra.py
:start-after: [Code]
:end-before: [End]
.. _examples-build123d_customizable_logo:
The build123d customizable logo
--------------------------------
.. image:: assets/examples/example_build123d_customizable_logo_01.png
:align: center
This example creates the build123d customizable logo.
It shows how text is created, placed and sizes of text is calulated to define sizes of other elements.
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/build123d_customizable_logo.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/build123d_customizable_logo_algebra.py
:start-after: [Code]
:end-before: [End]
.. _examples-build123d_logo:
Former build123d Logo
@ -256,6 +245,101 @@ This example demonstrates placing holes around a part.
:end-before: [End]
.. _clock_face:
Clock Face
----------
.. image:: assets/examples/clock_face.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/clock.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/clock_algebra.py
:start-after: [Code]
:end-before: [End]
The Python code utilizes the build123d library to create a 3D model of a clock face.
It defines a minute indicator with arcs and lines, applying fillets, and then
integrates it into the clock face sketch. The clock face includes a circular outline,
hour labels, and slots at specified positions. The resulting 3D model represents
a detailed and visually appealing clock design.
:class:`~build_common.PolarLocations` are used to position features on the clock face.
.. _handle:
Handle
------
.. image:: assets/examples/handle.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/handle.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/handle_algebra.py
:start-after: [Code]
:end-before: [End]
This example demonstrates multisection sweep creating a drawer handle.
.. _heat_exchanger:
Heat Exchanger
--------------
.. image:: assets/examples/heat_exchanger.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/heat_exchanger.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/heat_exchanger_algebra.py
:start-after: [Code]
:end-before: [End]
This example creates a model of a parametric heat exchanger core. The positions
of the tubes are defined with :class:`~build_common.HexLocations` and further
limited to fit within the circular end caps. The ends of the tubes are filleted
to the end plates to simulate welding.
.. _key_cap:
Key Cap
-------
.. image:: assets/examples/key_cap.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/key_cap.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/key_cap_algebra.py
:start-after: [Code]
:end-before: [End]
This example demonstrates the design of a Cherry MX key cap by using
extrude with a taper and extrude until next.
.. _maker_coin:
Maker Coin
@ -279,6 +363,57 @@ YouTube channel. There are two key features:
:start-after: [Code]
:end-before: [End]
.. _multi_sketch_loft:
Multi-Sketch Loft
-----------------
.. image:: assets/examples/loft.png
:align: center
This example demonstrates lofting a set of sketches, selecting
the top and bottom by type, and shelling.
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/loft.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/loft_algebra.py
:start-after: [Code]
:end-before: [End]
.. _peg_board_hook:
Peg Board Hook
--------------
.. image:: assets/examples/peg_board_hook.png
:align: center
This script creates a a J-shaped pegboard hook. These hooks are commonly used for
organizing tools in garages, workshops, or other spaces where tools and equipment
need to be stored neatly and accessibly. The hook is created by defining a complex
path and then sweeping it to define the hook. The sides of the hook are flattened
to aid 3D printing.
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/pegboard_j_hook.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/pegboard_j_hook_algebra.py
:start-after: [Code]
:end-before: [End]
.. _platonic_solids:
Platonic Solids
@ -304,6 +439,24 @@ embodying ideals of symmetry and balance.
:start-after: [Code]
:end-before: [End]
.. _playing_cards:
PLaying Cards
-------------
.. image:: assets/examples/playing_cards.png
:align: center
This example creates a customs Sketch objects: Club, Spade, Heart, Diamond,
and PlayingCard in addition to a two part playing card box which has suit
cutouts in the lid. The four suits are created with Bézier curves that were
imported as code from an SVG file and modified to the code found here.
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/playing_cards.py
:start-after: [Code]
:end-before: [End]
.. _stud_wall:
Stud Wall
@ -323,6 +476,75 @@ are used to position all of objects.
:start-after: [Code]
:end-before: [End]
.. _tea_cup:
Tea Cup
-------
.. image:: assets/examples/tea_cup.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/tea_cup.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/tea_cup_algebra.py
:start-after: [Code]
:end-before: [End]
This example demonstrates the creation a tea cup, which serves as an example of
constructing complex, non-flat geometrical shapes programmatically.
The tea cup model involves several CAD techniques, such as:
* Revolve Operations: There is 1 occurrence of a revolve operation. This is used
to create the main body of the tea cup by revolving a profile around an axis,
a common technique for generating symmetrical objects like cups.
* Sweep Operations: There are 2 occurrences of sweep operations. The handle are
created by sweeping a profile along a path to generate non-planar surfaces.
* Offset/Shell Operations: the bowl of the cup is hollowed out with the offset
operation leaving the top open.
* Fillet Operations: There is 1 occurrence of a fillet operation which is used to
round the edges for aesthetic improvement and to mimic real-world objects more
closely.
.. _vase:
Vase
----
.. image:: assets/examples/vase.png
:align: center
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
.. literalinclude:: ../examples/vase.py
:start-after: [Code]
:end-before: [End]
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
.. literalinclude:: ../examples/vase_algebra.py
:start-after: [Code]
:end-before: [End]
This example demonstrates the build123d techniques involving the creation of a vase.
Specifically, it showcases the processes of revolving a sketch, shelling
(creating a hollow object by removing material from its interior), and
selecting edges by position range and type for the application of fillets
(rounding off the edges).
* Sketching: Drawing a 2D profile or outline that represents the side view of
the vase.
* Revolving: Rotating the sketch around an axis to create a 3D object. This
step transforms the 2D profile into a 3D vase shape.
* Offset/Shelling: Removing material from the interior of the solid vase to
create a hollow space, making it resemble a real vase more closely.
* Edge Filleting: Selecting specific edges of the vase for filleting, which
involves rounding those edges. The edges are selected based on their position
and type.
.. NOTE 02: insert new example thumbnails above this line

View file

@ -27,6 +27,7 @@ license:
limitations under the License.
"""
# [Imports]
from build123d import *
from ocp_vscode import *
@ -51,9 +52,7 @@ with BuildPart() as benchy:
roof_vertices.group_by(Axis.Y, tol_digits=2)[0].sort_by(Axis.X)[0],
]
roof_plane = Plane(
Face.make_from_wires(
Wire.make_polygon([v.to_tuple() for v in roof_plane_vertices])
)
Face(Wire.make_polygon([v.to_tuple() for v in roof_plane_vertices]))
)
# Remove the faceted smoke stack
split(bisect_by=roof_plane, keep=Keep.BOTTOM)

View file

@ -33,6 +33,7 @@ image_files:
- "example_benchy_02.png"
- "example_benchy_03.png"
"""
# [Imports]
from build123d import *
from ocp_vscode import *
@ -57,9 +58,7 @@ with BuildPart() as benchy:
roof_vertices.group_by(Axis.Y, tol_digits=2)[0].sort_by(Axis.X)[0],
]
roof_plane = Plane(
Face.make_from_wires(
Wire.make_polygon([v.to_tuple() for v in roof_plane_vertices])
)
Face(Wire.make_polygon([v.to_tuple() for v in roof_plane_vertices]))
)
# Remove the faceted smoke stack
split(bisect_by=roof_plane, keep=Keep.BOTTOM)

View file

@ -24,6 +24,7 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Imports]
from build123d import *
from ocp_vscode import *
@ -95,7 +96,7 @@ with BuildSketch() as build:
with Locations((logo_width / 2, -6)):
add(cust_text.sketch)
cmpd = Compound.make_compound(
cmpd = Compound(
[three_d.part, two.sketch, one.line, build.sketch, extension_lines.line]
)

View file

@ -43,7 +43,7 @@ l2 = Line(
)
extension_lines = l1 + l2
extension_lines += Pos(*(l1 @ 0.5)) * arrow_left
extension_lines += (Pos(*(l2 @ 0.5)) * Rot(z=180)) * arrow_left
extension_lines += (Pos(*(l2 @ 0.5)) * Rot(Z=180)) * arrow_left
extension_lines += Line(l1 @ 0.5, l1 @ 0.5 + Vector(dim_line_length, 0))
extension_lines += Line(l2 @ 0.5, l2 @ 0.5 - Vector(dim_line_length, 0))
@ -55,7 +55,7 @@ build = p1 * build_text
p2 = Pos((l1 @ 1 + l2 @ 1) / 2 - Vector(cust_bb.max.X + cust_bb.min.X, 1.4))
build += p2 * cust_text
cmpd = Compound.make_compound([three_d, two, one, build, extension_lines])
cmpd = Compound([three_d, two, one, build, extension_lines])
if "show_object" in locals():
show_object(cmpd, name="compound")

View file

@ -1,6 +1,7 @@
"""
for details see `build123d_logo.py`
"""
# [Imports]
from build123d import *
from ocp_vscode import *
@ -46,7 +47,7 @@ extension_lines += Line(l2 @ 0.5, l2 @ 0.5 - Vector(dim_line_length, 0))
p1 = Pos((l1 @ 0.5 + l2 @ 0.5) / 2 - Vector((build_bb.max.X + build_bb.min.X) / 2, 0))
build = p1 * build_text
cmpd = Compound.make_compound([three_d, two, one, build, extension_lines])
cmpd = Compound([three_d, two, one, build, extension_lines])
show_object(cmpd, name="compound")

View file

@ -22,7 +22,7 @@ image_files:
# [Imports]
from math import sin, cos, pi
from build123d import *
from ocp_vscode import show_object
from ocp_vscode import show_object, show
# [Parameters]
# Canadian Flags have a 2:1 aspect ratio
@ -32,6 +32,7 @@ wave_amplitude = 3
# [Code]
def surface(amplitude, u, v):
"""Calculate the surface displacement of the flag at a given position"""
return v * amplitude / 20 * cos(3.5 * pi * u) + amplitude / 10 * v * sin(
@ -92,17 +93,14 @@ maple_leaf_planar = maple_leaf_builder.sketch.faces()[0]
center_field_planar = center_field_builder.sketch.faces()[0]
west_field = west_field_planar.project_to_shape(the_wind, (0, 0, -1))[0]
west_field.color = Color("red")
east_field = east_field_planar.project_to_shape(the_wind, (0, 0, -1))[0]
east_field.color = Color("red")
center_field = center_field_planar.project_to_shape(the_wind, (0, 0, -1))[0]
center_field.color = Color("white")
maple_leaf = maple_leaf_planar.project_to_shape(the_wind, (0, 0, -1))[0]
maple_leaf.color = Color("red")
# show_object(
# the_wind,
# name="the_wind",
# options={"alpha": 0.8, "color": (170 / 255, 85 / 255, 255 / 255)},
# )
show_object(west_field, name="west", options={"color": (255, 0, 0)})
show_object(east_field, name="east", options={"color": (255, 0, 0)})
show_object(center_field, name="center", options={"color": (255, 255, 255)})
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
canadian_flag = Compound(children=[west_field, east_field, center_field, maple_leaf])
show(Rot(90, 0, 0) * canadian_flag)
# [End]

View file

@ -1,10 +1,11 @@
"""
for details see `canadian_flag.py`
"""
# [Imports]
from math import sin, cos, pi
from build123d import *
from ocp_vscode import *
from ocp_vscode import show
# [Parameters]
# Canadian Flags have a 2:1 aspect ratio
@ -12,6 +13,7 @@ height = 50
width = 2 * height
wave_amplitude = 3
# [Code]
def surface(amplitude, u, v):
"""Calculate the surface displacement of the flag at a given position"""
@ -81,13 +83,14 @@ maple_leaf_planar = scale_move(maple_leaf_planar)
center_field_planar = scale_move(center_field_planar)
west_field = project(west_field_planar)
west_field.color = Color("red")
east_field = project(east_field_planar)
east_field.color = Color("red")
center_field = project(center_field_planar)
center_field.color = Color("white")
maple_leaf = project(maple_leaf_planar)
maple_leaf.color = Color("red")
show_object(west_field, name="west", options={"color": (255, 0, 0)})
show_object(east_field, name="east", options={"color": (255, 0, 0)})
show_object(center_field, name="center", options={"color": (255, 255, 255)})
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
canadian_flag = Compound(children=[west_field, east_field, center_field, maple_leaf])
show(Rot(90, 0, 0) * canadian_flag)
# [End]

View file

@ -6,7 +6,13 @@ date: July 15th 2022
desc:
This example demonstrates using polar coordinates in a sketch.
The Python code utilizes the build123d library to create a 3D model of a clock face.
It defines a minute indicator with arcs and lines, applying fillets, and then
integrates it into the clock face sketch. The clock face includes a circular outline,
hour labels, and slots at specified positions. The resulting 3D model represents
a detailed and visually appealing clock design.
PolarLocations are used to position features on the clock face.
license:
@ -24,7 +30,11 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import show
clock_radius = 10
with BuildSketch() as minute_indicator:
@ -51,5 +61,5 @@ with BuildSketch() as clock_face:
mode=Mode.SUBTRACT,
)
if "show_object" in locals():
show_object(clock_face.sketch.wrapped, name="clock_face")
show(clock_face)
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show
clock_radius = 10
@ -28,5 +31,5 @@ clock_face -= [
)
]
if "show_object" in locals():
show_object(clock_face)
show(clock_face)
# [End]

View file

@ -27,7 +27,9 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
from build123d import *
from ocp_vscode import show
class Club(BaseSketchObject):
@ -169,6 +171,4 @@ with BuildPart() as lid_builder:
extrude(amount=-wall_t, mode=Mode.SUBTRACT)
lid = lid_builder.part.moved(Location((0, 0, (wall_t + pocket_t) / 2)))
if "show_object" in locals():
show_object(box, name="box")
show_object(lid, name="lid", options={"alpha": 0.6})
show(box, lid, names=["box", "lid"], alphas=[1.0, 0.6])

View file

@ -1,12 +1,13 @@
from typing import Tuple, Union
from typing import Union
from build123d import *
from ocp_vscode import show
class Club(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
align: Union[Align, tuple[Align, Align]] = None,
):
l0 = Line((0, -188), (76, -188))
b0 = Bezier(l0 @ 1, (61, -185), (33, -173), (17, -81))
@ -26,7 +27,7 @@ class Spade(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
align: Union[Align, tuple[Align, Align]] = None,
):
b0 = Bezier((0, 198), (6, 190), (41, 127), (112, 61))
b1 = Bezier(b0 @ 1, (242, -72), (114, -168), (11, -105))
@ -45,7 +46,7 @@ class Heart(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
align: Union[Align, tuple[Align, Align]] = None,
):
b1 = Bezier((0, 146), (20, 169), (67, 198), (97, 198))
b2 = Bezier(b1 @ 1, (125, 198), (151, 186), (168, 167))
@ -65,7 +66,7 @@ class Diamond(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
align: Union[Align, tuple[Align, Align]] = None,
):
diamond = Bezier((135, 0), (94, 69), (47, 134), (0, 198))
diamond += mirror(diamond, Plane.XZ)
@ -110,6 +111,4 @@ suites = plane * suites
lid = pocket - extrude(suites, dir=(0, 0, 1), amount=-wall_t)
if "show_object" in locals():
show_object(box, name="box")
show_object(lid, name="lid", options={"alpha": 0.6})
show(box, lid, names=["box", "lid"], alphas=[1.0, 0.6])

View file

@ -26,8 +26,10 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
from build123d import *
from ocp_vscode import show
logging.basicConfig(
filename="din_rail.log",
@ -81,5 +83,4 @@ with BuildPart() as rail:
extrude(amount=height, mode=Mode.SUBTRACT)
# assert abs(rail.part.volume - 42462.863388694714) < 1e-3
if "show_object" in locals():
show_object(rail.part.wrapped, name="rail")
show(rail, names=["rail"])

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show
# 35x7.5mm DIN Rail Dimensions
overall_width, top_width, height, thickness, fillet_radius = 35, 27, 7.5, 1, 0.8
@ -45,5 +46,4 @@ slot_faces = [
rail -= extrude(slot_faces, -height)
rail = Plane.XZ * rail
if "show_object" in locals():
show_object(rail, name="rail")
show(rail, names=["rail"])

View file

@ -25,11 +25,10 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
from build123d import *
from ocp_vscode import *
set_port(3940)
# Extrude pending face by amount
with BuildPart() as simple:
with BuildSketch():
@ -97,10 +96,7 @@ with BuildPart() as ex27:
# Rectangle(rad, rev)
# extrusion28 = extrude(until=Until.NEXT, both=True)
if "show_object" in locals():
show_object(
simple.part.translate((-15, 0, 0)).wrapped, name="simple pending extrude"
)
show_object(simple.part.translate((-15, 0, 0)).wrapped, name="simple pending extrude")
show_object(both.part.translate((20, 10, 0)).wrapped, name="simple both")
show_object(
multiple.part.translate((0, -20, 0)).wrapped, name="multiple pending extrude"

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show_object
# Extrude pending face by amount
simple = extrude(Text("O", font_size=10), amount=5)
@ -20,8 +21,7 @@ non_planar = Rot(90, 0, 0) * Cylinder(
10, 20, align=(Align.CENTER, Align.MIN, Align.CENTER)
)
non_planar &= Box(10, 10, 10, align=(Align.CENTER, Align.CENTER, Align.MIN))
non_planar = extrude(non_planar.faces().sort_by(Axis.Z).first, amount=2)
non_planar = extrude(non_planar.faces().sort_by(Axis.Z).first, amount=2, dir=(0, 0, 1))
rad, rev = 3, 25
# Extrude last
@ -44,11 +44,10 @@ extrusion27 = extrude(rect, until=Until.NEXT, target=ex27, mode=Mode.ADD)
# Extrude next both
ex28 = Rot(0, 90, 0) * Torus(25, 5)
rect = Rectangle(rad, rev)
extrusion28 = extrude(rect, until=Until.NEXT, target=ex28, both=True, clean=False)
# ex28 = Rot(0, 90, 0) * Torus(25, 5)
# rect = Rectangle(rad, rev)
# extrusion28 = extrude(rect, until=Until.NEXT, target=ex28, both=True, clean=False)
if "show_object" in locals():
show_object(simple.translate((-15, 0, 0)), name="simple pending extrude")
show_object(both.translate((20, 10, 0)), name="simple both")
show_object(multiple.translate((0, -20, 0)), name="multiple pending extrude")
@ -71,12 +70,12 @@ if "show_object" in locals():
extrusion27.rotate(Axis.Z, 90).translate((0, 50, 0)),
name="extrude until next",
)
show_object(
ex28.rotate(Axis.Z, -90).translate((0, -50, 0)),
name="extrude until next both target",
options={"alpha": 0.8},
)
show_object(
extrusion28.rotate(Axis.Z, -90).translate((0, -50, 0)),
name="extrude until next both",
)
# show_object(
# ex28.rotate(Axis.Z, -90).translate((0, -50, 0)),
# name="extrude until next both target",
# options={"alpha": 0.8},
# )
# show_object(
# extrusion28.rotate(Axis.Z, -90).translate((0, -50, 0)),
# name="extrude until next both",
# )

View file

@ -24,7 +24,11 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import show_object
segment_count = 6
@ -62,8 +66,8 @@ with BuildPart() as handle:
assert abs(handle.part.volume - 94.77361455046953) < 1e-3
if "show_object" in locals():
show_object(handle_path.wrapped, name="handle_path")
for i, section in enumerate(sections):
show_object(section.wrapped, name="section" + str(i))
show_object(handle.part.wrapped, name="handle", options=dict(alpha=0.6))
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show_object
segment_count = 6
@ -32,8 +35,8 @@ for i in range(segment_count + 1):
# Create the handle by sweeping along the path
handle = sweep(sections, path=handle_path, multisection=True)
if "show_object" in locals():
show_object(handle_path.wrapped, name="handle_path")
for i, circle in enumerate(sections):
show_object(circle.wrapped, name="section" + str(i))
show_object(handle, name="handle", options=dict(alpha=0.6))
# [End]

View file

@ -24,7 +24,11 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import show
exchanger_diameter = 10 * CM
exchanger_length = 30 * CM
@ -81,5 +85,5 @@ with BuildPart() as heat_exchanger:
fillet_volume = 2 * (half_volume_after_fillet - half_volume_before_fillet)
assert abs(fillet_volume - 469.88331045553787) < 1e-3
if "show_object" in locals():
show_object(heat_exchanger.part.wrapped)
show(heat_exchanger)
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show
exchanger_diameter = 10 * CM
exchanger_length = 30 * CM
@ -51,5 +54,5 @@ heat_exchanger += mirror(heat_exchanger, Plane.XY)
fillet_volume = 2 * (half_volume_after_fillet - half_volume_before_fillet)
assert abs(fillet_volume - 469.88331045553787) < 1e-3
if "show_object" in locals():
show_object(heat_exchanger.wrapped)
show(heat_exchanger)
# [End]

View file

@ -24,7 +24,9 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
from build123d import *
from ocp_vscode import show_object
# Simple through hole
with BuildPart() as thru_hole:
@ -52,7 +54,6 @@ with BuildPart() as flush_counter_sink:
):
CounterSinkHole(radius=1, counter_sink_radius=1.5)
if "show_object" in locals():
show_object(thru_hole.part.wrapped, name="though hole")
show_object(recessed_counter_bore.part.wrapped, name="recessed counter bore")
show_object(recessed_counter_sink.part.wrapped, name="recessed counter sink")

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show_object
thru_hole = Cylinder(radius=3, height=2)
thru_hole -= Hole(radius=1, depth=2)
@ -20,7 +21,6 @@ flush_counter_sink -= plane * CounterSinkHole(
radius=1, depth=2, counter_sink_radius=1.5
)
if "show_object" in locals():
show_object(thru_hole, name="though hole")
show_object(Pos(10, 0) * recessed_counter_bore, name="recessed counter bore")
show_object(Pos(0, 10) * recessed_counter_sink, name="recessed counter sink")

View file

@ -1,5 +1,5 @@
from build123d import *
from ocp_vscode import show
with BuildPart() as blocks:
with Locations((-1, -1, 0)):
@ -15,5 +15,4 @@ with BuildPart() as blocks:
chamfer(top_edges, length=0.1)
if "show_object" in locals():
show_object(blocks.part.wrapped)
show(blocks)

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show
blocks = Pos(-1, -1, 0) * Box(1, 2, 1, align=(Align.CENTER, Align.MIN, Align.MIN))
blocks += Box(1, 1, 2, align=(Align.CENTER, Align.MIN, Align.MIN))
@ -11,5 +12,4 @@ top_edges = blocks2.edges().filter_by_position(Axis.Z, 1, 2, inclusive=(False, T
blocks2 = chamfer(top_edges, length=0.1)
if "show_object" in locals():
show_object(blocks2)
show(blocks2)

View file

@ -25,8 +25,10 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
from build123d import *
from ocp_vscode import show
# logging.basicConfig(
# filename="intersecting_pipes.log",
@ -48,5 +50,4 @@ with BuildPart() as pipes:
assert abs(pipes.part.volume - 1015.939005681509) < 1e-3
if "show_object" in locals():
show_object(pipes.part.wrapped, name="intersecting pipes")
show(pipes, names=["intersecting pipes"])

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show
pipes = Rot(10, 20, 30) * Box(10, 10, 10)
@ -12,5 +13,4 @@ for plane in [Plane(f) for f in pipes.faces()]:
pipes += extrude(pipe, amount=10)
pipes = fillet(pipes.edges() - last, 0.2)
if "show_object" in locals():
show_object(pipes, name="intersecting pipes")
show(pipes, names=["intersecting pipes"])

View file

@ -27,6 +27,9 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import *
@ -65,3 +68,4 @@ with BuildPart() as key_cap:
assert abs(key_cap.part.volume - 644.8900473617498) < 1e-3
show(key_cap, alphas=[0.3])
# [End]

View file

@ -1,3 +1,5 @@
# [Code]
from build123d import *
from ocp_vscode import *
@ -39,3 +41,4 @@ socket -= Rectangle(1.17 * MM, 4.1 * MM)
key_cap += extrude(Plane(rib_bottom) * socket, amount=3.5 * MM)
show(key_cap, alphas=[0.3])
# [End]

View file

@ -25,8 +25,12 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from math import pi, sin
from build123d import *
from ocp_vscode import show
with BuildPart() as art:
slice_count = 10
@ -39,5 +43,5 @@ with BuildPart() as art:
assert abs(art.part.volume - 1306.3405290344635) < 1e-3
if "show_object" in locals():
show_object(art.part.wrapped, name="art")
show(art, names=["art"])
# [End]

View file

@ -1,5 +1,8 @@
# [Code]
from math import pi, sin
from build123d import *
from ocp_vscode import show
slice_count = 10
@ -12,5 +15,5 @@ art = loft(art)
top_bottom = art.faces().filter_by(GeomType.PLANE)
art = offset(art, openings=top_bottom, amount=0.5)
if "show_object" in locals():
show_object(art, name="art")
show(art, names=["art"])
# [End]

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show_object
# Mix context and algebra api for parts
@ -30,7 +31,6 @@ with BuildLine() as bl:
e = bl.line + ThreePointArc((-1, 0), (-1.5, 0.5), (-1, 1))
if "show_object" in locals():
show_object(Pos(0, -2, 0) * c, "part")
show_object(Pos(0, 2, 0) * d, "sketch")
show_object(Pos(0, 0, 2) * e, "curve")

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show
with BuildPart() as obj:
Box(5, 5, 1)
@ -7,5 +8,4 @@ with BuildPart() as obj:
assert abs(obj.part.volume - 15.083039190168236) < 1e-3
if "show_object" in locals():
show_object(obj.part)
show(obj)

View file

@ -1,8 +1,8 @@
from build123d import *
from ocp_vscode import show
obj = Box(5, 5, 1)
planes = [Plane(f) for f in obj.faces().filter_by(Axis.Z)]
obj -= planes * Sphere(1.8)
if "show_object" in locals():
show_object(obj)
show(obj)

View file

@ -19,7 +19,10 @@ license:
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import show
pegd = 6.35 + 0.1 # mm ~0.25inch
c2c = 25.4 # mm 1.0inch
@ -69,5 +72,5 @@ with BuildPart() as mainp:
split(bisect_by=Plane(origin=(0, 0, -splitz)))
split(bisect_by=Plane(origin=(0, 0, splitz)), keep=Keep.BOTTOM)
if "show_object" in locals():
show_object(mainp.part.wrapped)
show(mainp)
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show
pegd = 6.35 + 0.1 # mm ~0.25inch
c2c = 25.4 # mm 1.0inch
@ -33,7 +36,7 @@ l7 = PolarLine(
direction=l6 % 1,
)
sprof = Curve() + (l1, l2, l3, l4, l5, l6, l7)
wire = Wire.make_wire(sprof.edges()) # TODO sprof.wires() fails
wire = Wire(sprof.edges()) # TODO sprof.wires() fails
mainp = sweep(Plane.YZ * Circle(radius=maind / 2), path=wire)
stub = Line((0, 0), (0, midx + maind / 2))
@ -44,5 +47,5 @@ mainp += sweep(Plane.XZ * Circle(radius=midd / 2), path=stub)
mainp = split(mainp, Plane(origin=(0, 0, -splitz)))
mainp = split(mainp, Plane(origin=(0, 0, splitz)), keep=Keep.BOTTOM)
if "show_object" in locals():
show_object(mainp)
show(mainp)
# [End]

View file

@ -25,7 +25,9 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
from build123d import *
from ocp_vscode import show
height, width, thickness, padding = 60, 80, 10, 12
screw_shaft_radius, screw_head_radius, screw_head_height = 1.5, 3, 3
@ -44,5 +46,4 @@ with BuildPart() as pillow_block:
CounterBoreHole(screw_shaft_radius, screw_head_radius, screw_head_height)
# Render the part
if "show_object" in locals():
show_object(pillow_block.part.wrapped)
show(pillow_block)

View file

@ -115,9 +115,7 @@ class PlatonicSolid(BasePartObject):
platonic_faces = []
for face_vertex_indices in hull:
corner_vertices = [platonic_vertices[i] for i in face_vertex_indices]
platonic_faces.append(
Face.make_from_wires(Wire.make_polygon(corner_vertices))
)
platonic_faces.append(Face(Wire.make_polygon(corner_vertices)))
# Create the solid from the Faces
platonic_solid = Solid.make_solid(Shell.make_shell(platonic_faces)).clean()

View file

@ -7,6 +7,9 @@ date: Jan 21st 2023
desc:
This example demonstrates user generated custom BuildSketch objects.
The script defines five classes: Club, Spade, Heart, Diamond, and PlayingCard
in addition to a two part playing card box which has suit cutouts in the
lid.
license:
@ -24,8 +27,12 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from typing import Literal
from build123d import *
from ocp_vscode import show_object
# [Club]
@ -156,7 +163,7 @@ with BuildPart() as lid_builder:
Club(card_length / 5)
extrude(amount=-wall, mode=Mode.SUBTRACT)
box = Compound.make_compound(
box = Compound(
[box_builder.part, lid_builder.part.moved(Location((0, 0, (wall + deck) / 2)))]
)
visible, hidden = box.project_to_viewport((70, -50, 120))
@ -166,28 +173,31 @@ exporter.add_layer("Visible")
exporter.add_layer("Hidden", line_color=(99, 99, 99), line_type=LineType.ISO_DOT)
exporter.add_shape(visible, layer="Visible")
exporter.add_shape(hidden, layer="Hidden")
exporter.write(f"assets/card_box.svg")
# exporter.write(f"assets/card_box.svg")
class PlayingCard(Compound):
class PlayingCard(BaseSketchObject):
"""PlayingCard
A standard playing card modelled as a Face.
Args:
rank (Literal['A', '2' .. '9', 'J', 'Q', 'K']): card rank
rank (Literal['A', '2' .. '10', 'J', 'Q', 'K']): card rank
suit (Literal['Clubs', 'Spades', 'Hearts', 'Diamonds']): card suit
"""
width = 2.5 * IN
height = 3.5 * IN
suits = {"Clubs": Club, "Spades": Spade, "Hearts": Heart, "Diamonds": Diamond}
ranks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K"]
ranks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
def __init__(
self,
rank: Literal["A", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K"],
rank: Literal["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"],
suit: Literal["Clubs", "Spades", "Hearts", "Diamonds"],
rotation: float = 0,
align: tuple[Align, Align] = (Align.CENTER, Align.CENTER),
mode: Mode = Mode.ADD,
):
with BuildSketch() as playing_card:
Rectangle(
@ -253,30 +263,37 @@ class PlayingCard(Compound):
rotation=suit_rotation,
mode=Mode.SUBTRACT,
)
super().__init__(playing_card.sketch.wrapped)
super().__init__(
obj=playing_card.sketch, rotation=rotation, align=align, mode=mode
)
playing_card = PlayingCard(rank="A", suit="Spades")
ace_spades = PlayingCard(rank="A", suit="Spades", align=Align.MIN)
ace_spades.color = Color("white")
king_hearts = PlayingCard(rank="K", suit="Hearts", align=Align.MIN)
king_hearts.color = Color("white")
queen_clubs = PlayingCard(rank="Q", suit="Clubs", align=Align.MIN)
queen_clubs.color = Color("white")
jack_diamonds = PlayingCard(rank="J", suit="Diamonds", align=Align.MIN)
jack_diamonds.color = Color("white")
ten_spades = PlayingCard(rank="10", suit="Spades", align=Align.MIN)
ten_spades.color = Color("white")
if "show_object" in locals():
show_object(playing_card)
# show_object(outer_box_builder.part, "outer")
# show_object(b, name="b", options={"alpha": 0.8})
hand = Compound(
children=[
Rot(0, 0, -20) * Pos(0, 0, 0) * ace_spades,
Rot(0, 0, -10) * Pos(0, 0, -1) * king_hearts,
Rot(0, 0, 0) * Pos(0, 0, -2) * queen_clubs,
Rot(0, 0, 10) * Pos(0, 0, -3) * jack_diamonds,
Rot(0, 0, 20) * Pos(0, 0, -4) * ten_spades,
]
)
show_object(Pos(-20, 40) * hand)
show_object(box_builder.part, "box_builder")
show_object(
lid_builder.part.moved(Location((0, 0, (wall + deck) / 2))),
Pos(0, 0, (wall + deck) / 2) * lid_builder.part,
"lid_builder",
options={"alpha": 0.7},
)
# show_object(walls.sketch, "walls")
# show_object(o, "o")
# show_object(half_club.line)
# show_object(spade_outline.line)
# show_object(b0, "b0")
# show_object(b1, "b1")
# show_object(b2, "b2")
# show_object(b3, "b3")
# show_object(b4, "b4")
# show_object(b5, "b5")
# show_object(l0, "l0")
# show_object(l0, "l0")
# [End]

View file

@ -1,210 +0,0 @@
from typing import Tuple, Union, Literal
from build123d import *
class Club(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
):
l0 = Line((0, -188), (76, -188))
b0 = Bezier(l0 @ 1, (61, -185), (33, -173), (17, -81))
b1 = Bezier(b0 @ 1, (49, -128), (146, -145), (167, -67))
b2 = Bezier(b1 @ 1, (187, 9), (94, 52), (32, 18))
b3 = Bezier(b2 @ 1, (92, 57), (113, 188), (0, 188))
club = l0 + b0 + b1 + b2 + b3
club += mirror(club, about=Plane.YZ)
club = make_face(club)
club = scale(club, by=height / club.bounding_box().size.Y)
super().__init__(club.wrapped)
# self._align(align)
class Spade(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
):
b0 = Bezier((0, 198), (6, 190), (41, 127), (112, 61))
b1 = Bezier(b0 @ 1, (242, -72), (114, -168), (11, -105))
b2 = Bezier(b1 @ 1, (31, -174), (42, -179), (53, -198))
l0 = Line(b2 @ 1, (0, -198))
spade = l0 + b0 + b1 + b2
spade += mirror(spade, about=Plane.YZ)
spade = make_face(spade)
spade = scale(spade, by=height / spade.bounding_box().size.Y)
super().__init__(spade.wrapped)
# self._align(align)
class Heart(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
):
b1 = Bezier((0, 146), (20, 169), (67, 198), (97, 198))
b2 = Bezier(b1 @ 1, (125, 198), (151, 186), (168, 167))
b3 = Bezier(b2 @ 1, (197, 133), (194, 88), (158, 31))
b4 = Bezier(b3 @ 1, (126, -13), (94, -48), (62, -95))
b5 = Bezier(b4 @ 1, (40, -128), (0, -198))
heart = b1 + b2 + b3 + b4 + b5
heart += mirror(objects=heart, about=Plane.YZ)
heart = make_face(heart)
heart = scale(heart, by=height / heart.bounding_box().size.Y)
super().__init__(heart.wrapped)
# self._align(align)
class Diamond(Sketch):
def __init__(
self,
height: float,
align: Union[Align, Tuple[Align, Align]] = None,
):
diamond = Bezier((135, 0), (94, 69), (47, 134), (0, 198))
diamond += mirror(diamond, about=Plane.XZ)
diamond += mirror(diamond, about=Plane.YZ)
diamond = make_face(diamond)
diamond = scale(diamond, by=height / diamond.bounding_box().size.Y)
super().__init__(diamond.wrapped)
# self._align(align)
# The inside of the box fits 2.5x3.5" playing card deck with a small gap
pocket_w = 2.5 * IN + 2 * MM
pocket_l = 3.5 * IN + 2 * MM
pocket_t = 0.5 * IN + 2 * MM
wall_t = 3 * MM # Wall thickness
bottom_t = wall_t / 2 # Top and bottom thickness
lid_gap = 0.5 * MM # Spacing between base and lid
lip_t = wall_t / 2 - lid_gap / 2 # Lip thickness
box_plan = RectangleRounded(pocket_w + 2 * wall_t, pocket_l + 2 * wall_t, pocket_w / 15)
box = extrude(box_plan, amount=bottom_t + pocket_t / 2)
base_top = box.faces().sort_by(Axis.Z).last
walls = Plane(base_top) * offset(box_plan, -lip_t)
box += extrude(walls, amount=pocket_t / 2)
top = Plane.XY.offset(wall_t / 2) * offset(box_plan, -wall_t)
box -= extrude(top, amount=pocket_t)
pocket = extrude(box_plan, amount=pocket_t / 2 + bottom_t)
lid_bottom = offset(box_plan, -(wall_t - lip_t))
pocket -= extrude(lid_bottom, amount=pocket_t / 2)
pocket = Pos(0, 0, (wall_t + pocket_t) / 2) * pocket
plane = Plane(pocket.faces().sort_by().last)
suites = Pos(-0.3 * pocket_w, -0.3 * pocket_l) * Heart(pocket_l / 5)
suites += Pos(-0.3 * pocket_w, 0.3 * pocket_l) * Diamond(pocket_l / 5)
suites += Pos(0.3 * pocket_w, -0.3 * pocket_l) * Spade(pocket_l / 5)
suites += Pos(0.3 * pocket_w, 0.3 * pocket_l) * Club(pocket_l / 5)
suites = plane * suites
lid = pocket - extrude(suites, dir=(0, 0, 1), amount=-wall_t)
class PlayingCard(Compound):
"""PlayingCard
A standard playing card modelled as a Face.
Args:
rank (Literal['A', '2' .. '9', 'J', 'Q', 'K']): card rank
suit (Literal['Clubs', 'Spades', 'Hearts', 'Diamonds']): card suit
"""
width = 2.5 * IN
height = 3.5 * IN
suits = {"Clubs": Club, "Spades": Spade, "Hearts": Heart, "Diamonds": Diamond}
ranks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K"]
def __init__(
self,
rank: Literal["A", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K"],
suit: Literal["Clubs", "Spades", "Hearts", "Diamonds"],
):
w = PlayingCard.width
h = PlayingCard.height
playing_card = Rectangle(w, h, align=Align.MIN)
if "show" in locals():
show(playing_card)
playing_card = fillet(playing_card.vertices(), radius=w / 15)
if "show" in locals():
show(playing_card)
playing_card -= Pos(w / 7, 8 * h / 9) * Text(
txt=rank,
font_size=w / 7,
)
if "show" in locals():
show(playing_card)
playing_card -= Pos(w / 7, 7 * h / 9,) * PlayingCard.suits[
suit
](height=w / 12)
if "show" in locals():
show(playing_card)
playing_card -= (
Pos((6 * w / 7, 1 * h / 9))
* Rot(0, 0, 180)
* Text(txt=rank, font_size=w / 7)
)
if "show" in locals():
show(playing_card)
playing_card -= (
Pos((6 * w / 7, 2 * h / 9))
* Rot(0, 0, 180)
* PlayingCard.suits[suit](height=w / 12)
)
if "show" in locals():
show(playing_card)
rank_int = PlayingCard.ranks.index(rank) + 1
rank_int = rank_int if rank_int < 10 else 1
center_radius = 0 if rank_int == 1 else w / 3.5
suit_rotation = 0 if rank_int == 1 else -90
suit_height = (0.00159 * rank_int**2 - 0.0380 * rank_int + 0.37) * w
playing_card -= (
Pos(w / 2, h / 2)
* Pos(
radius=center_radius,
count=rank_int,
start_angle=90 if rank_int > 1 else 0,
)
* Rot(0, 0, suit_rotation)
* PlayingCard.suits[suit](
height=suit_height,
)
)
super().__init__(playing_card.wrapped)
playing_card = PlayingCard(rank="A", suit="Spades")
if "show_object" in locals():
show_object(playing_card)
# show_object(outer_box_builder.part, "outer")
# show_object(b, name="b", options={"alpha": 0.8})
show_object(box, "box")
show_object(lid, "lid", options={"alpha": 0.7})
# show_object(walls.sketch, "walls")
# show_object(o, "o")
# show_object(half_club.line)
# show_object(spade_outline.line)
# show_object(b0, "b0")
# show_object(b1, "b1")
# show_object(b2, "b2")
# show_object(b3, "b3")
# show_object(b4, "b4")
# show_object(b5, "b5")
# show_object(l0, "l0")
# show_object(l0, "l0")

View file

@ -25,7 +25,9 @@ license:
limitations under the License.
"""
from build123d import *
from ocp_vscode import show_object
# A sphere used as a projection target
sphere = Solid.make_sphere(50, angle1=-90)
@ -35,7 +37,7 @@ projection_direction = Vector(0, 1, 0)
square = Face.make_rect(20, 20, Plane.ZX.offset(-80))
square_projected = square.project_to_shape(sphere, projection_direction)
square_solids = Compound.make_compound([f.thicken(2) for f in square_projected])
square_solids = Compound([f.thicken(2) for f in square_projected])
projection_beams = [
Solid.make_loft(
[
@ -50,14 +52,14 @@ projection_direction = Vector(0, -1, 0)
flat_planar_text_faces = (
Compound.make_text("Flat", font_size=30).rotate(Axis.X, 90).faces()
)
flat_projected_text_faces = Compound.make_compound(
flat_projected_text_faces = Compound(
[
f.project_to_shape(sphere, projection_direction)[0]
for f in flat_planar_text_faces
]
).moved(Location((-100, -100)))
flat_projection_beams = Compound.make_compound(
[Solid.extrude_linear(f, projection_direction * 80) for f in flat_planar_text_faces]
flat_projection_beams = Compound(
[Solid.extrude(f, projection_direction * 80) for f in flat_planar_text_faces]
).moved(Location((-100, -100)))
@ -75,13 +77,12 @@ text = Compound.make_text(
)
projected_text = sphere.project_faces(text, path=arch_path)
if "show_object" in locals():
# Example 1
show_object(sphere, name="sphere_solid", options={"alpha": 0.8})
show_object(square, name="square")
show_object(square_solids, name="square_solids")
show_object(
Compound.make_compound(projection_beams),
Compound(projection_beams),
name="projection_beams",
options={"alpha": 0.9, "color": (170 / 255, 170 / 255, 255 / 255)},
)
@ -105,6 +106,4 @@ if "show_object" in locals():
name="sphere_solid for text on path",
options={"alpha": 0.8},
)
show_object(
projected_text.moved(Location((100, 100))), name="projected_text on path"
)
show_object(projected_text.moved(Location((100, 100))), name="projected_text on path")

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show_object
# A sphere used as a projection target
sphere = Sphere(50)
@ -40,13 +41,12 @@ text = Text(
)
projected_text = sphere.project_faces(text.faces(), path=arch_path)
if "show_object" in locals():
# Example 1
show_object(sphere, name="sphere_solid", options={"alpha": 0.8})
show_object(square, name="square")
show_object(square_solids, name="square_solids")
show_object(
Compound.make_compound(projection_beams),
Compound(projection_beams),
name="projection_beams",
options={"alpha": 0.9, "color": (170 / 255, 170 / 255, 255 / 255)},
)
@ -72,6 +72,4 @@ if "show_object" in locals():
name="sphere_solid for text on path",
options={"alpha": 0.8},
)
show_object(
projected_text.moved(Location((100, 100))), name="projected_text on path"
)
show_object(projected_text.moved(Location((100, 100))), name="projected_text on path")

View file

@ -1,4 +1,5 @@
from build123d import *
from ocp_vscode import show
class Shamrock(BaseSketchObject):
@ -46,9 +47,7 @@ class Shamrock(BaseSketchObject):
)
if __name__ == "__main__" or "show_object" in locals():
with BuildSketch() as shamrock_example:
Shamrock(10)
if "show_object" in locals():
show_object(shamrock_example.sketch)
show(shamrock_example)

View file

@ -4,7 +4,20 @@ name: tea_cup.py
by: Gumyr
date: March 27th 2023
desc: This example demonstrates the creation of non-planar objects.
desc: This example demonstrates the creation a tea cup, which serves as an example of
constructing complex, non-flat geometrical shapes programmatically.
The tea cup model involves several CAD techniques, such as:
- Revolve Operations: There is 1 occurrence of a revolve operation. This is used
to create the main body of the tea cup by revolving a profile around an axis,
a common technique for generating symmetrical objects like cups.
- Sweep Operations: There are 2 occurrences of sweep operations. The handle are
created by sweeping a profile along a path to generate non-planar surfaces.
- Offset/Shell Operations: the bowl of the cup is hollowed out with the offset
operation leaving the top open.
- Fillet Operations: There is 1 occurrence of a fillet operation which is used to
round the edges for aesthetic improvement and to mimic real-world objects more
closely.
license:
@ -22,7 +35,11 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
# [Code]
from build123d import *
from ocp_vscode import show
wall_thickness = 3 * MM
fillet_radius = wall_thickness * 0.49
@ -75,5 +92,5 @@ with BuildPart() as tea_cup:
assert abs(tea_cup.part.volume - 130326) < 1
if "show_object" in locals():
show_object(tea_cup.part, name="tea cup")
show(tea_cup, names=["tea cup"])
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show
wall_thickness = 3 * MM
fillet_radius = wall_thickness * 0.49
@ -54,5 +57,5 @@ tea_cup += sweep(handle_cross_section, path=path_spline)
# assert abs(tea_cup.part.volume - 130326.77052487945) < 1e-3
if "show_object" in locals():
show_object(tea_cup, name="tea cup")
show(tea_cup, names=["tea cup"])
# [End]

View file

@ -6,8 +6,21 @@ date: July 15th 2022
desc:
This example demonstrates revolving a sketch, shelling and selecting edges
by position range and type for fillets.
This example demonstrates the build123d techniques involving the creation of a vase.
Specifically, it showcases the processes of revolving a sketch, shelling
(creating a hollow object by removing material from its interior), and
selecting edges by position range and type for the application of fillets
(rounding off the edges).
- Sketching: Drawing a 2D profile or outline that represents the side view of
the vase.
- Revolving: Rotating the sketch around an axis to create a 3D object. This
step transforms the 2D profile into a 3D vase shape.
- Offset/Shelling: Removing material from the interior of the solid vase to
create a hollow space, making it resemble a real vase more closely.
- Edge Filleting: Selecting specific edges of the vase for filleting, which
involves rounding those edges. The edges are selected based on their position
and type.
license:
@ -25,11 +38,11 @@ license:
See the License for the specific language governing permissions and
limitations under the License.
"""
from build123d import *
from ocp_vscode import show, show_object, set_port, set_defaults
set_port(3939)
set_defaults(reset_camera=True, ortho=True)
# [Code]
from build123d import *
from ocp_vscode import show_object
with BuildPart() as vase:
with BuildSketch() as profile:
@ -60,6 +73,5 @@ with BuildPart() as vase:
fillet(vase.edges().sort_by(Axis.Y)[0], radius=0.5)
# show_object(outline, name="outline")
# show_object(profile, name="profile")
show_object(vase, name="vase")
show_object(Rot(90, 0, 0) * vase.part, name="vase")
# [End]

View file

@ -1,4 +1,7 @@
# [Code]
from build123d import *
from ocp_vscode import show_object
l1 = Line((0, 0), (12, 0))
l2 = RadiusArc(l1 @ 1, (15, 20), 50)
@ -26,5 +29,5 @@ vase = fillet(top_edges, radius=0.25)
vase = fillet(vase.edges().sort_by(Axis.Y).first, radius=0.5)
if "show_object" in locals():
show_object(vase, name="vase")
show_object(Rot(90, 0, 0) * vase, name="vase")
# [End]