Ops

⚙️ Spec sheet →  —  visual schematic and metrics measured from a real rendered STL.

Boolean operations, offsets, text and cross helpers.

pybosl2.shapes2d.ops.osimport(file, convexity=None, layer=None, dpi=None, center=None, id=None)[source]

Import a 2-D drawing (SVG or DXF) as a Bosl2Shape2D (OpenSCAD import()).

The wrapped counterpart of the bare native osimport(), so an imported outline joins the fluent API instead of being a raw handle a caller has to keep unwrapping – it can be offset, filled, hulled, coloured and extruded like any other 2-D shape.

Relative paths resolve against the PROCESS working directory, not the calling module, so pass an absolute path if the asset lives beside your source.

Use pybosl2.shapes3d.osimport() for 3-D meshes (STL/OFF/3MF).

Parameters:
file : str

Path to the drawing to import.

convexity : int | None

Convexity hint for preview rendering.

layer : str | None

For DXF, the layer to import.

dpi : float | None

For SVG, dots per inch used to convert lengths.

center : bool | None

Center the imported drawing on the origin.

id : str | None

For SVG, the id of the single element to import.

Returns:

A Bosl2Shape2D wrapping the imported outline.

Return type:

CsgShape2D

Examples

Import a 2-D drawing, resize it and extrude:

from pybosl2 import shapes2d as s2

s2.osimport("drawing.svg").resize([40, 40, 0]).linear_extrude(height=2).show()
pybosl2.shapes2d.ops.fill(children)[source]

children with every hole filled in – only the outermost outline survives.

(OpenSCAD fill(), the module form of Bosl2Shape2D.fill()).

Parameters:
children : Shape2DLike

the 2-D shape to fill (a Bosl2Shape2D, a native shape, a Path2D / Region, or a point list)

Return type:

Bosl2Shape2D

pybosl2.shapes2d.ops.hull(*children)[source]

Return the 2-D convex hull of children (OpenSCAD hull(), the module form of.

Bosl2Shape2D.hull()).

Parameters:
children : Shape2DLike | Sequence[Shape2DLike]

the 2-D shapes to hull – any mix of Bosl2Shape2D, native shapes, Path2D / Region, or point lists. A single list/tuple of shapes is also accepted.

Return type:

Bosl2Shape2D

pybosl2.shapes2d.ops.round2d(radius=None, outer_radius=None, inner_radius=None, children=None, fn=None, fa=None, fs=None)[source]

Round the concave and/or convex corners of arbitrary 2-D children, via chained .offset() calls.

Giving radius rounds all corners; inner_radius alone rounds only concave corners; outer_radius alone rounds only convex corners; giving both rounds each to a different radius.

Note: BOSL2’s outer-radius parameter is named or, exposed here as outer_radius.

Parameters:
radius : float | None

radius to round all concave and convex corners to

outer_radius : float | None

radius to round only convex (outside) corners to (BOSL2 or)

inner_radius : float | None

radius to round only concave (inside) corners to

children : Bosl2Shape2D | PyOpenSCAD | None

the 2-D solid(s) to round

fn : int | None

arc smoothness overrides. Omitted, the ambient use_defaults(fn=...) value applies; fn=0 opts back out to fa/fs.

fa : float | None

arc smoothness overrides. Omitted, the ambient use_defaults(fa=...) value applies.

fs : float | None

arc smoothness overrides. Omitted, the ambient use_defaults(fs=...) value applies.

Return type:

Bosl2Shape2D

pybosl2.shapes2d.ops.shell2d(thickness=None, outer_radius=0, inner_radius=0, children=None, fn=None, fa=None, fs=None)[source]

Create a hollow shell from 2-D children, with optional rounding.

Note: BOSL2’s outer-radius parameter is named or, exposed here as outer_radius.

Parameters:
thickness : float | Sequence[float] | None

shell thickness; positive expands outward, negative shrinks inward, or a 2-element list to do both

outer_radius : float | Sequence[float]

rounding radius for outside corners of the shell (BOSL2 or); a [CONVEX,CONCAVE] pair rounds those corner types separately (default 0)

inner_radius : float | Sequence[float]

rounding radius for inside corners of the shell; a [CONVEX,CONCAVE] pair rounds those corner types separately (default 0)

children : Bosl2Shape2D | PyOpenSCAD | None

the 2-D solid(s) to shell

fn : int | None

arc smoothness overrides. Omitted, the ambient use_defaults(fn=...) value applies; fn=0 opts back out to fa/fs.

fa : float | None

arc smoothness overrides. Omitted, the ambient use_defaults(fa=...) value applies.

fs : float | None

arc smoothness overrides. Omitted, the ambient use_defaults(fs=...) value applies.

Return type:

Bosl2Shape2D

pybosl2.shapes2d.ops.cross(size=(10, 10), arm_width=None, center=None, anchor=Anchor.CENTER, spin=0)[source]

Return a 2-D cross (plus) shape: two perpendicular centred rectangles.

Parameters:
size : float | Sequence[float]

overall size, a scalar square or [width, length] (default [10, 10]).

arm_width : float | Sequence[float] | None

width of each arm; a scalar or [horizontal, vertical] pair. When None (default) the arms are one-third of the overall size.

center : bool | None

centre alignment (default True).

anchor : Anchor | Sequence[float]

anchor point (default CENTER).

spin : float

Z-axis rotation in degrees after anchor (default 0).

Returns:

A Bosl2Shape2D wrapping the cross polygon.

Return type:

Bosl2Shape2D

Examples

from pybosl2 import shapes2d as s2

s2.cross(size=30).linear_extrude(height=5).show()
Loading 3-D preview…

⬇ Download STL mesh

pybosl2.shapes2d.ops.text(text, size=10, font='Liberation Sans', halign=None, valign=None, spacing=1.0, direction='ltr', language='en', script='latin', anchor=None, spin=0, fn=None, fa=None, fs=None)[source]

Create 2-D text (halign/valign supported natively).

Parameters:
text : str

text to create

size : float

font size (default 10)

font : str

font to use (default “Liberation Sans”)

halign : str | None

horizontal alignment: “left”, “center”, “right” (default “center”)

valign : str | None

vertical alignment: “top”, “center”, “baseline”, “bottom” (default “baseline”)

spacing : float

relative spacing multiplier between characters (default 1.0)

direction : str

text direction: “ltr”, “rtl”, “ttb”, “btt” (default “ltr”)

language : str

language the text is in (default “en”)

script : str

script the text is in (default “latin”)

anchor : Anchor | Sequence[float] | None

where the finished text’s bounding box lands, in the anchor language (SPEC C-10). None leaves it where halign/valign put it, which is the typographic placement and the usual answer for text

spin : float

Z-axis rotation in degrees (default 0)

fn : int | None

number of fragments for circle resolution. Omitted, the ambient use_defaults(fn=...) value applies; fn=0 opts back out to fa/fs.

fa : float | None

minimum fragment angle for circle resolution. Omitted, the ambient use_defaults(fa=...) value applies.

fs : float | None

minimum fragment size for circle resolution. Omitted, the ambient use_defaults(fs=...) value applies.

Return type:

Bosl2Shape2D