Open Source Python Library for 2D & 3D CAD Drawings
Open source Python CAD Library for Creating and Managing 2D & 3D Models. Create Parametric Lego Block & Use Selectors inside Python apps.
What is Build123d Library?
Build123d is an open source Python 3D CAD package helping software developers to create 2D & 3D drawings inside their own Python applications. The Build123d library uses the standard python context manager and three builders are available for handling drawings. The BuildLine builder can be used for one-dimensional objects, BuildSketch builder for planar two-dimensional objects, and BuildPart builder for three-dimensional objects. A builder uses Location Contexts for positioning objects or operations.
The library has included support for various 2D and 3D operations, such as fillet, mirror, offset, scale, split, CounterBoreHole, CounterSinkHole, Extrude, Hole, Loft, Revolve, Scale, Section, Split, and many more. Apart from the above, there are several selectors, selector operators, edge and wire operators, plane operators, vector operators, and vertex operators are also part of the library.
Build123d library is a useful alternative to the Build123d API having many advantages over it and the most important one is that build123d enables the full python toolbox when designing objects. The library is very simple to operate and one can easily position and manage objects anywhere.
Getting Started with Build123d
The easiest way to install Build123d stable release is using GitHub. Please use the following command for a smooth installation
Install Build123d via GitHub
python3 -m pip install git+https://github.com/gumyr/build123d.git#egg=build123d
You can download the compiled shared library from Github repository.
How to Use Selectors via Python Library
AWhen using a GUI based CAD system the user will often click on a feature to select it for some operation. Selectors are procedures that show how users can separate a feature from a design using python filter and sorting methods typically implemented as a set of custom python operations. vertices(),edges(), wires(), solids() and faces() are some example of selectors. The operand types are: Axis, SortBy, and GeomType. Please remember that standard list methods like sorted or filtered are helpful in generating complex selectors.
Create Parametric Lego Block via Python Library
The Open source Python Library Build123d allows software developers to created parametric Lego block inside their own Python applications. First you need to important the build123d environment and define the dimensions of the Lego block. Now we can move to the builder part and need to create the internal structure of the blocks. For structure we need to draw a two dimensional sketch that will later be extruded into a three dimensional object. After that we can define perimeter rectangle and create walls of the block rectangle and create internal grid. After that we need to convert the internal grid to ridges, the center needs to be removed. Now create set of internal hollow cylinders and extrude Sketch into Walls. After the completion of walls, the top of the block needs to be added and the final step is to add the pips.
How to Create Dimensions & Internal Grid of Lego Block via Python API?
from build123d import *
pip_count = 6
lego_unit_size = 8
pip_height = 1.8
pip_diameter = 4.8
block_length = lego_unit_size * pip_count
block_width = 16
base_height = 9.6
block_height = base_height + pip_height
support_outer_diameter = 6.5
support_inner_diameter = 4.8
ridge_width = 0.6
ridge_depth = 0.3
wall_thickness = 1.2
// instantiate a BuildPart
with BuildPart() as lego:
//create a sketch builder
with BuildPart() as lego:
# Draw the bottom of the block
with BuildSketch() as plan:
//create Perimeter Rectangle
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)
//create the walls of the block
ith 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)
# Subtract an offset to create the block walls
Offset(
perimeter,
amount=-wall_thickness,
kind=Kind.INTERSECTION,
mode=Mode.SUBTRACT,
)
//Create Internal Grid
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)
# Subtract an offset to create the block walls
Offset(
perimeter,
amount=-wall_thickness,
kind=Kind.INTERSECTION,
mode=Mode.SUBTRACT,
)
# 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)