mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-05 18:20:46 -08:00
modified example for review example_1.rst
modified: examples/benchy.py new file: examples/benchy_v2024.py modified: examples/boxes_on_faces.py modified: examples/boxes_on_faces_algebra.py modified: examples/build123d_customizable_logo.py modified: examples/build123d_customizable_logo_algebra.py modified: examples/build123d_logo_algebra.py
This commit is contained in:
parent
05477c4bce
commit
a836505173
7 changed files with 119 additions and 1 deletions
|
|
@ -27,15 +27,19 @@ license:
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# [Imports]
|
||||||
from build123d import *
|
from build123d import *
|
||||||
from ocp_vscode import *
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Parameters]
|
||||||
|
# - none
|
||||||
|
|
||||||
|
# [Code]
|
||||||
# Import the benchy as a Solid model
|
# Import the benchy as a Solid model
|
||||||
importer = Mesher()
|
importer = Mesher()
|
||||||
benchy_stl = importer.read("low_poly_benchy.stl")[0]
|
benchy_stl = importer.read("low_poly_benchy.stl")[0]
|
||||||
|
|
||||||
with BuildPart() as benchy:
|
with BuildPart() as benchy:
|
||||||
# Add benchy
|
|
||||||
add(benchy_stl)
|
add(benchy_stl)
|
||||||
|
|
||||||
# Determine the plane that defines the top of the roof
|
# Determine the plane that defines the top of the roof
|
||||||
|
|
@ -77,3 +81,4 @@ with BuildPart() as benchy:
|
||||||
extrude(amount=roof_plane_vertices[1].Z - smoke_stack_center.Z)
|
extrude(amount=roof_plane_vertices[1].Z - smoke_stack_center.Z)
|
||||||
|
|
||||||
show(benchy)
|
show(benchy)
|
||||||
|
# [End]
|
||||||
|
|
|
||||||
90
examples/benchy_v2024.py
Normal file
90
examples/benchy_v2024.py
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
"""
|
||||||
|
name: "benchy.py"
|
||||||
|
title: "Low Poly Benchy"
|
||||||
|
authors: "Gumyr"
|
||||||
|
license: "http://www.apache.org/licenses/LICENSE-2.0"
|
||||||
|
created: "2023-07-09"
|
||||||
|
modified: "2024-01-09"
|
||||||
|
|
||||||
|
description: |
|
||||||
|
STL import and edit example.
|
||||||
|
|
||||||
|
The Benchy examples shows hot to import a STL model as a `Solid` object and change it.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
*Attribution:*
|
||||||
|
The low-poly-benchy used in this example is by `reddaugherty`, see
|
||||||
|
https://www.printables.com/model/151134-low-poly-benchy.
|
||||||
|
|
||||||
|
|
||||||
|
.. dropdown:: Info
|
||||||
|
|
||||||
|
- uses file `low_poly_benchy.stl`
|
||||||
|
- uses `class Mesher`
|
||||||
|
- uses `group_by` and `sort_by`
|
||||||
|
- uses `make_polygon`
|
||||||
|
- uses `split`
|
||||||
|
|
||||||
|
has_builder_mode: true
|
||||||
|
has_algebra_mode: false
|
||||||
|
image_files:
|
||||||
|
- "example_benchy_01.png"
|
||||||
|
- "example_benchy_02.png"
|
||||||
|
- "example_benchy_03.png"
|
||||||
|
"""
|
||||||
|
# [Imports]
|
||||||
|
from build123d import *
|
||||||
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Parameters]
|
||||||
|
# - none
|
||||||
|
|
||||||
|
# [Code]
|
||||||
|
# Import the benchy as a Solid model
|
||||||
|
importer = Mesher()
|
||||||
|
benchy_stl = importer.read("low_poly_benchy.stl")[0]
|
||||||
|
|
||||||
|
with BuildPart() as benchy:
|
||||||
|
add(benchy_stl)
|
||||||
|
|
||||||
|
# Determine the plane that defines the top of the roof
|
||||||
|
vertices = benchy.vertices()
|
||||||
|
roof_vertices = vertices.filter_by_position(Axis.Z, 38, 42)
|
||||||
|
roof_plane_vertices = [
|
||||||
|
roof_vertices.group_by(Axis.Y, tol_digits=2)[-1].sort_by(Axis.X)[0],
|
||||||
|
roof_vertices.sort_by(Axis.Z)[0],
|
||||||
|
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])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# Remove the faceted smoke stack
|
||||||
|
split(bisect_by=roof_plane, keep=Keep.BOTTOM)
|
||||||
|
|
||||||
|
# Determine the position and size of the smoke stack
|
||||||
|
smoke_stack_vertices = vertices.group_by(Axis.Z, tol_digits=0)[-1]
|
||||||
|
smoke_stack_center = sum(
|
||||||
|
[Vector(v.X, v.Y, v.Z) for v in smoke_stack_vertices], Vector()
|
||||||
|
) * (1 / len(smoke_stack_vertices))
|
||||||
|
smoke_stack_radius = max(
|
||||||
|
[
|
||||||
|
(Vector(*v.to_tuple()) - smoke_stack_center).length
|
||||||
|
for v in smoke_stack_vertices
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create the new smoke stack
|
||||||
|
with BuildSketch(Plane(smoke_stack_center)):
|
||||||
|
Circle(smoke_stack_radius)
|
||||||
|
Circle(smoke_stack_radius - 2 * MM, mode=Mode.SUBTRACT)
|
||||||
|
extrude(amount=-3 * MM)
|
||||||
|
with BuildSketch(Plane(smoke_stack_center)):
|
||||||
|
Circle(smoke_stack_radius - 0.5 * MM)
|
||||||
|
Circle(smoke_stack_radius - 2 * MM, mode=Mode.SUBTRACT)
|
||||||
|
extrude(amount=roof_plane_vertices[1].Z - smoke_stack_center.Z)
|
||||||
|
|
||||||
|
show(benchy)
|
||||||
|
# [End]
|
||||||
|
|
@ -23,8 +23,11 @@ license:
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# [Imports]
|
||||||
import build123d as bd
|
import build123d as bd
|
||||||
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Code]
|
||||||
with bd.BuildPart() as bp:
|
with bd.BuildPart() as bp:
|
||||||
bd.Box(3, 3, 3)
|
bd.Box(3, 3, 3)
|
||||||
with bd.BuildSketch(*bp.faces()):
|
with bd.BuildSketch(*bp.faces()):
|
||||||
|
|
@ -35,3 +38,4 @@ assert abs(bp.part.volume - (3**3 + 6 * (1 * 2 * 0.1)) < 1e-3)
|
||||||
|
|
||||||
if "show_object" in locals():
|
if "show_object" in locals():
|
||||||
show_object(bp.part.wrapped, name="box on faces")
|
show_object(bp.part.wrapped, name="box on faces")
|
||||||
|
# [End]
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
|
# license see [build123d_license](../LICENSE)
|
||||||
|
# [Imports]
|
||||||
from build123d import *
|
from build123d import *
|
||||||
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Code]
|
||||||
b = Box(3, 3, 3)
|
b = Box(3, 3, 3)
|
||||||
b2 = Rot(0, 0, 45) * extrude(Rectangle(1, 2), 0.1)
|
b2 = Rot(0, 0, 45) * extrude(Rectangle(1, 2), 0.1)
|
||||||
for plane in [Plane(f) for f in b.faces()]:
|
for plane in [Plane(f) for f in b.faces()]:
|
||||||
|
|
@ -7,3 +11,4 @@ for plane in [Plane(f) for f in b.faces()]:
|
||||||
|
|
||||||
if "show_object" in locals():
|
if "show_object" in locals():
|
||||||
show_object(b, name="box on faces")
|
show_object(b, name="box on faces")
|
||||||
|
# [End]
|
||||||
|
|
@ -24,9 +24,14 @@ license:
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
# [Imports]
|
||||||
from build123d import *
|
from build123d import *
|
||||||
from ocp_vscode import *
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Parameters]
|
||||||
|
# - none
|
||||||
|
|
||||||
|
# [Code]
|
||||||
with BuildSketch() as logo_text:
|
with BuildSketch() as logo_text:
|
||||||
Text("123d", font_size=10, align=(Align.MIN, Align.MIN))
|
Text("123d", font_size=10, align=(Align.MIN, Align.MIN))
|
||||||
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
||||||
|
|
@ -106,3 +111,5 @@ show_object(cmpd, name="compound")
|
||||||
# show_object(three_d.part.wrapped, name="three_d")
|
# show_object(three_d.part.wrapped, name="three_d")
|
||||||
# show_object(extension_lines.line.wrapped, name="extension_lines")
|
# show_object(extension_lines.line.wrapped, name="extension_lines")
|
||||||
# show_object(build.sketch.wrapped, name="build")
|
# show_object(build.sketch.wrapped, name="build")
|
||||||
|
|
||||||
|
# [End]
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
|
# [Imports]
|
||||||
from build123d import *
|
from build123d import *
|
||||||
|
from ocp_vscode import *
|
||||||
|
|
||||||
|
# [Parameters]
|
||||||
|
|
||||||
|
# [Code]
|
||||||
logo_text = Text("123d", font_size=10, align=Align.MIN)
|
logo_text = Text("123d", font_size=10, align=Align.MIN)
|
||||||
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
||||||
|
|
||||||
|
|
@ -59,3 +64,4 @@ if "show_object" in locals():
|
||||||
# show_object(three_d.part.wrapped, name="three_d")
|
# show_object(three_d.part.wrapped, name="three_d")
|
||||||
# show_object(extension_lines.line.wrapped, name="extension_lines")
|
# show_object(extension_lines.line.wrapped, name="extension_lines")
|
||||||
# show_object(build.sketch.wrapped, name="build")
|
# show_object(build.sketch.wrapped, name="build")
|
||||||
|
# [End]
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from build123d import *
|
from build123d import *
|
||||||
|
from ocp_vscode import *
|
||||||
|
|
||||||
logo_text = Text("123d", font_size=10, align=Align.MIN)
|
logo_text = Text("123d", font_size=10, align=Align.MIN)
|
||||||
font_height = logo_text.vertices().sort_by(Axis.Y).last.Y
|
font_height = logo_text.vertices().sort_by(Axis.Y).last.Y
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue