diff --git a/docs/assets/lego.svg b/docs/assets/lego.svg
new file mode 100644
index 0000000..cb43cde
--- /dev/null
+++ b/docs/assets/lego.svg
@@ -0,0 +1,415 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step10.svg b/docs/assets/lego_step10.svg
new file mode 100644
index 0000000..6d31bd0
--- /dev/null
+++ b/docs/assets/lego_step10.svg
@@ -0,0 +1,305 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step4.svg b/docs/assets/lego_step4.svg
new file mode 100644
index 0000000..c57d50e
--- /dev/null
+++ b/docs/assets/lego_step4.svg
@@ -0,0 +1,8 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step5.svg b/docs/assets/lego_step5.svg
new file mode 100644
index 0000000..93657bc
--- /dev/null
+++ b/docs/assets/lego_step5.svg
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step6.svg b/docs/assets/lego_step6.svg
new file mode 100644
index 0000000..3df5e43
--- /dev/null
+++ b/docs/assets/lego_step6.svg
@@ -0,0 +1,29 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step7.svg b/docs/assets/lego_step7.svg
new file mode 100644
index 0000000..9fc66ca
--- /dev/null
+++ b/docs/assets/lego_step7.svg
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step8.svg b/docs/assets/lego_step8.svg
new file mode 100644
index 0000000..8e0545f
--- /dev/null
+++ b/docs/assets/lego_step8.svg
@@ -0,0 +1,19 @@
+
+
\ No newline at end of file
diff --git a/docs/assets/lego_step9.svg b/docs/assets/lego_step9.svg
new file mode 100644
index 0000000..8176ee3
--- /dev/null
+++ b/docs/assets/lego_step9.svg
@@ -0,0 +1,355 @@
+
+
\ No newline at end of file
diff --git a/docs/tutorial_lego.rst b/docs/tutorial_lego.rst
index 9c54638..f079ec3 100644
--- a/docs/tutorial_lego.rst
+++ b/docs/tutorial_lego.rst
@@ -5,7 +5,7 @@ Lego Tutorial
This tutorial provides a step by step guide to creating a script to build a parametric
Lego block as shown here:
-.. image:: tutorial_lego.svg
+.. image:: assets/lego.svg
:align: center
*************
@@ -21,7 +21,7 @@ The dimensions of the Lego block follow. A key parameter is ``pip_count``, the l
of the Lego blocks in pips. This parameter must be at least 2.
.. literalinclude:: ../examples/lego.py
- :lines: 29-44
+ :lines: 29, 32-45
********************
Step 2: Part Builder
@@ -31,7 +31,7 @@ The Lego block will be created by the ``BuildPart`` builder as it's a discrete t
dimensional part; therefore, we'll instantiate a ``BuildPart`` with the name ``lego``.
.. literalinclude:: ../examples/lego.py
- :lines: 52
+ :lines: 47
**********************
Step 3: Sketch Builder
@@ -43,7 +43,7 @@ object. As this sketch will be part of the lego part, we'll create a sketch bui
in the context of the part builder as follows:
.. literalinclude:: ../examples/lego.py
- :lines: 52-54
+ :lines: 47-49
:emphasize-lines: 3
@@ -59,12 +59,12 @@ of the Lego block. The following step is going to refer to this rectangle, so it
be assigned the identifier ``perimeter``.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56
+ :lines: 47-51
:emphasize-lines: 5
Once the ``Rectangle`` object is created the sketch appears as follows:
-.. image:: tutorial_step4.svg
+.. image:: assets/lego_step4.svg
:align: center
******************************
@@ -76,7 +76,7 @@ hollowed out. This will be done with the ``Offset`` operation which is going to
create a new object from ``perimeter``.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66
+ :lines: 47-51,55-61
:emphasize-lines: 7-12
The first parameter to ``Offset`` is the reference object. The ``amount`` is a
@@ -86,7 +86,7 @@ square corners. Finally, the ``mode`` parameter controls how this object will
be placed in the sketch - in this case subtracted from the existing sketch.
The result is shown here:
-.. image:: tutorial_step5.svg
+.. image:: assets/lego_step5.svg
:align: center
Now the sketch consists of a hollow rectangle.
@@ -104,7 +104,7 @@ objects are in the scope of a location context (``GridLocations`` in this case)
that defined multiple points, multiple rectangles are created.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74
+ :lines: 47-51,55-61,65-69
:emphasize-lines: 13-17
Here we can see that the first ``GridLocations`` creates two positions which causes
@@ -114,7 +114,7 @@ parameter are optional in this case.
The result looks like this:
-.. image:: tutorial_step6.svg
+.. image:: assets/lego_step6.svg
:align: center
*********************
@@ -125,12 +125,12 @@ To convert the internal grid to ridges, the center needs to be removed. This wil
with another ``Rectangle``.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74,79-83
- :emphasize-lines: 18-22
+ :lines: 47-51,55-61,65-69,74-78
+ :emphasize-lines: 17-22
The ``Rectangle`` is subtracted from the sketch to leave the ridges as follows:
-.. image:: tutorial_step7.svg
+.. image:: assets/lego_step7.svg
:align: center
@@ -142,8 +142,8 @@ Lego blocks use a set of internal hollow cylinders that the pips push against
to hold two blocks together. These will be created with ``Circle``.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74,79-83,87-92
- :emphasize-lines: 23-28
+ :lines: 47-51,55-61,65-69,74-76,82-87
+ :emphasize-lines: 21-26
Here another ``GridLocations`` is used to position the centers of the circles. Note
that since both ``Circle`` objects are in the scope of the location context, both
@@ -151,7 +151,7 @@ Circles will be positioned at these locations.
Once the Circles are added, the sketch is complete and looks as follows:
-.. image:: tutorial_step8.svg
+.. image:: assets/lego_step8.svg
:align: center
***********************************
@@ -162,8 +162,8 @@ Now that the sketch is complete it needs to be extruded into the three dimension
wall object.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74,79-83,87-92,96-97
- :emphasize-lines: 29-30
+ :lines: 47-51,55-61,65-69,74-76,82-87,91-92
+ :emphasize-lines: 27-28
Note how the ``Extrude`` operation is no longer in the ``BuildSketch`` scope and has returned
back into the ``BuildPart`` scope. This causes ``BuildSketch`` to exit and transfer the
@@ -171,7 +171,7 @@ sketch that we've created to ``BuildPart`` for further processing by ``Extrude``
The result is:
-.. image:: tutorial_step9.svg
+.. image:: assets/lego_step9.svg
:align: center
@@ -183,8 +183,8 @@ Now that the walls are complete, the top of the block needs to be added. Althoug
could be done with another sketch, we'll add a box to the top of the walls.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74,79-83,87-92,96-97,101-109
- :emphasize-lines: 31-39
+ :lines: 47-51,55-61,65-69,74-76,82-87,91-92,100-108
+ :emphasize-lines: 29-37
To position the top, we'll describe the top center of the lego walls with a ``Locations`` context.
To determine the height we'll extract that from the
@@ -200,7 +200,7 @@ the intersection of the x and y axis but not in the z thus aligning with the top
The base is closed now as shown here:
-.. image:: tutorial_step10.svg
+.. image:: assets/lego_step10.svg
:align: center
********************
@@ -211,8 +211,8 @@ The final step is to add the pips to the top of the Lego block. To do this we'll
a new workplane on top of the block where we can position the pips.
.. literalinclude:: ../examples/lego.py
- :lines: 52-56,60-66,70-74,79-83,87-92,96-97,101-109,120-128
- :emphasize-lines: 40-48
+ :lines: 47-51,55-61,65-69,74-76,82-87,91-92,100-108,116-124
+ :emphasize-lines: 38-46
In this case, the workplane is created from the top Face of the Lego block by using the
``faces`` method and then sorted vertically and taking the top one ``sort_by(Axis.Z)[-1]``.
@@ -220,7 +220,7 @@ In this case, the workplane is created from the top Face of the Lego block by us
On the new workplane, a grid of locations is created and a number of ``Cylinder``'s are positioned
at each location.
-.. image:: tutorial_step11.svg
+.. image:: assets/lego.svg
:align: center
This completes the Lego block. To access the finished product, refer to the builder's internal
diff --git a/examples/lego.py b/examples/lego.py
index 91ab961..92d3771 100644
--- a/examples/lego.py
+++ b/examples/lego.py
@@ -27,6 +27,7 @@ license:
limitations under the License.
"""
from build123d import *
+from ocp_vscode import *
pip_count = 6
@@ -43,20 +44,14 @@ ridge_width = 0.6
ridge_depth = 0.3
wall_thickness = 1.2
-svg_opts = {
- "pixel_scale": 20,
- "show_axes": False,
- "show_hidden": False,
-}
-
with BuildPart() as lego:
# Draw the bottom of the block
with BuildSketch() as plan:
# Start with a Rectangle the size of the block
perimeter = Rectangle(width=block_length, height=block_width)
- plan.sketch.export_svg(
- "tutorial_step4.svg", (0, 0, 10), (0, 1, 0), svg_opts=svg_opts
- )
+ exporter = ExportSVG(scale=6)
+ exporter.add_shape(plan.sketch)
+ exporter.write("assets/lego_step4.svg")
# Subtract an offset to create the block walls
offset(
perimeter,
@@ -64,40 +59,44 @@ with BuildPart() as lego:
kind=Kind.INTERSECTION,
mode=Mode.SUBTRACT,
)
- plan.sketch.export_svg(
- "tutorial_step5.svg", (0, 0, 10), (0, 1, 0), svg_opts=svg_opts
- )
+ exporter = ExportSVG(scale=6)
+ exporter.add_shape(plan.sketch)
+ exporter.write("assets/lego_step5.svg")
# Add a grid of lengthwise and widthwise bars
with GridLocations(x_spacing=0, y_spacing=lego_unit_size, x_count=1, y_count=2):
Rectangle(width=block_length, height=ridge_width)
with GridLocations(lego_unit_size, 0, pip_count, 1):
Rectangle(width=ridge_width, height=block_width)
- plan.sketch.export_svg(
- "tutorial_step6.svg", (0, 0, 10), (0, 1, 0), svg_opts=svg_opts
- )
+ exporter = ExportSVG(scale=6)
+ exporter.add_shape(plan.sketch)
+ exporter.write("assets/lego_step6.svg")
# Substract a rectangle leaving ribs on the block walls
Rectangle(
block_length - 2 * (wall_thickness + ridge_depth),
block_width - 2 * (wall_thickness + ridge_depth),
mode=Mode.SUBTRACT,
)
- plan.sketch.export_svg(
- "tutorial_step7.svg", (0, 0, 10), (0, 1, 0), svg_opts=svg_opts
- )
+ exporter = ExportSVG(scale=6)
+ exporter.add_shape(plan.sketch)
+ exporter.write("assets/lego_step7.svg")
# Add a row of hollow circles to the center
with GridLocations(
x_spacing=lego_unit_size, y_spacing=0, x_count=pip_count - 1, y_count=1
):
Circle(radius=support_outer_diameter / 2)
Circle(radius=support_inner_diameter / 2, mode=Mode.SUBTRACT)
- plan.sketch.export_svg(
- "tutorial_step8.svg", (0, 0, 10), (0, 1, 0), svg_opts=svg_opts
- )
+ exporter = ExportSVG(scale=6)
+ exporter.add_shape(plan.sketch)
+ exporter.write("assets/lego_step8.svg")
# Extrude this base sketch to the height of the walls
extrude(amount=base_height - wall_thickness)
- lego.part.export_svg(
- "tutorial_step9.svg", (-5, -30, 50), (0, 0, 1), svg_opts=svg_opts
- )
+ visible, hidden = lego.part.project_to_viewport((-5, -30, 50))
+ exporter = ExportSVG(unit=Unit.MILLIMETER, scale=6)
+ 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("assets/lego_step9.svg")
# Create a box on the top of the walls
with Locations((0, 0, lego.vertices().sort_by(Axis.Z)[-1].Z)):
# Create the top of the block
@@ -107,16 +106,13 @@ with BuildPart() as lego:
height=wall_thickness,
align=(Align.CENTER, Align.CENTER, Align.MIN),
)
- lego.part.export_svg(
- "tutorial_step10.svg",
- (-5, -30, 50),
- (0, 0, 1),
- svg_opts={
- "pixel_scale": 20,
- "show_axes": False,
- "show_hidden": True,
- },
- )
+ visible, hidden = lego.part.project_to_viewport((-5, -30, 50))
+ exporter = ExportSVG(unit=Unit.MILLIMETER, scale=6)
+ 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("assets/lego_step10.svg")
# Create a workplane on the top of the block
with BuildPart(lego.faces().sort_by(Axis.Z)[-1]):
# Create a grid of pips
@@ -126,21 +122,14 @@ with BuildPart() as lego:
height=pip_height,
align=(Align.CENTER, Align.CENTER, Align.MIN),
)
- lego.part.export_svg(
- "tutorial_step11.svg", (-100, -100, 50), (0, 0, 1), svg_opts=svg_opts
- )
- lego.part.export_svg(
- "tutorial_lego.svg",
- (-100, -100, 50),
- (0, 0, 1),
- svg_opts={
- "pixel_scale": 20,
- "show_axes": False,
- "show_hidden": True,
- },
- )
+ visible, hidden = lego.part.project_to_viewport((-100, -100, 50))
+ exporter = ExportSVG(unit=Unit.MILLIMETER, scale=6)
+ 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("assets/lego.svg")
assert abs(lego.part.volume - 3212.187337781355) < 1e-3
-if "show_object" in locals():
- show_object(lego.part.wrapped, name="lego")
+show_object(lego.part.wrapped, name="lego")