API reference
Everything below is importable from smlibpy directly: from smlibpy import *.
Shapes
Part
Part()
A solid: one or more closed volumes.
Combine parts with + (union), - (difference) and & (intersection).
The right-hand side may be a single part or any iterable of parts.
area(property): Total surface area.bbox(): Tight axis-aligned bounding box.center(): Center of mass (uniform density).chamfer(edges, length): Bevel edges.lengthis the setback measured along both adjacent faces.closest_point(point):colored(color): The same body with a display color ("steelblue","#4682b4"or(r, g, b)).cut(*others): Subtract other parts.distance_to(other): Minimum distance to a point or to another body.draft(faces, angle, neutral_plane):edges(seams=False): All edges. Seam edges (where a closed surface such as a cylinder meets itself) are left out unlessseamsis true.export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.fillet(edges, radius, *, continuity=None, fullness=1.0): Round edges.fuse(*others): Union with other parts.heal(): Repair gaps, tolerances and topology (mostly needed for imported data).info(): Counts and measures in one dictionary.intersect(*others): Keep only the volume shared with the other parts.intersection_curves(other): The curves where this body's surface meets another body's surface.is_valid(): True if the part is a closed, manifold solid that encloses a positive volume.mass_properties(density=1.0, accuracy=None): Mass, center of mass and inertia tensor for a uniformdensity.mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).named(name): The same body with a name (used by exporters and the viewer).offset(distance): Grow (positive) or shrink (negative) the part bydistanceeverywhere.on(target): Place this shape, designed around the world XY plane, onto a plane or face.outline(plane=Plane.XY): The body's edges projected onto a plane (a 2D drawing view).project(curve, direction=(0, 0, -1)): Project a curve onto the body alongdirection; returns the curves on its faces.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).section(plane=Plane.XY): The cross-section of the part in a plane, as a sketch.shell(thickness, openings=None, *, outward=False): Hollow the part out to walls ofthickness, removing theopeningsfaces.show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).silhouette(direction=(0, 0, 1)): Silhouette curves on the body as seen alongdirection.solids(): The separate bodies of this part.split(plane, keep='above'): Cut the part with a plane.to_nurbs(): A copy whose faces and edges are all NURBS (analytic types converted).translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.volume(property):wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Sketch
Sketch()
A planar region (with holes, possibly several pieces) on a plane.
Sketch constructors build in the world XY plane around the origin; place a sketch
with .on(plane_or_face), Plane * sketch or Pos(...) * sketch. Combine
sketches with +, - and &, then turn them into parts with
extrude, revolve, sweep or smlibpy.loft.
area(property):bbox(): Tight axis-aligned bounding box.center(): Center of mass (centroid) of the shape.closest_point(point):colored(color): The same body with a display color ("steelblue","#4682b4"or(r, g, b)).distance_to(other): Minimum distance to a point or to another body.edges(seams=False): All edges. Seam edges (where a closed surface such as a cylinder meets itself) are left out unlessseamsis true.export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).extrude(amount, *, both=False, taper=0.0, direction=None): Extrude the region into a solid.faces(): All faces of this shape.fillet(radius, vertices=None): Round the corners of the region (between straight edges).heal(): Repair gaps, tolerances and topology (mostly needed for imported data).info(): Counts and measures in one dictionary.intersection_curves(other): The curves where this body's surface meets another body's surface.mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).named(name): The same body with a name (used by exporters and the viewer).offset(distance, *, round=True): Grow (positive) or shrink (negative) the region; corners are rounded or sharp.on(target): Place this shape, designed around the world XY plane, onto a plane or face.outline(plane=Plane.XY): The body's edges projected onto a plane (a 2D drawing view).plane(property): The sketch plane; extrusions follow its normal.project(curve, direction=(0, 0, -1)): Project a curve onto the body alongdirection; returns the curves on its faces.revolve(axis=None, angle=360.0): Revolve the region about an axis in its plane.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).silhouette(direction=(0, 0, 1)): Silhouette curves on the body as seen alongdirection.sweep(path, *, sharp_corners=None): Sweep the region along a path. The sketch should sit at the start of the path.thicken(thickness, *, both=False): Turn the sheet into a solid ofthickness(along the face normals; a negative thickness grows against them). Withboththe solid isthicknessthick in total, half of it to each side of the sheet.to_nurbs(): A copy whose faces and edges are all NURBS (analytic types converted).translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Shell
Shell()
A sheet body: one or more faces that do not enclose a volume (surfaces).
area(property):bbox(): Tight axis-aligned bounding box.center(): Center of mass (centroid) of the shape.closest_point(point):colored(color): The same body with a display color ("steelblue","#4682b4"or(r, g, b)).distance_to(other): Minimum distance to a point or to another body.edges(seams=False): All edges. Seam edges (where a closed surface such as a cylinder meets itself) are left out unlessseamsis true.export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.heal(): Repair gaps, tolerances and topology (mostly needed for imported data).info(): Counts and measures in one dictionary.intersection_curves(other): The curves where this body's surface meets another body's surface.mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).named(name): The same body with a name (used by exporters and the viewer).on(target): Place this shape, designed around the world XY plane, onto a plane or face.outline(plane=Plane.XY): The body's edges projected onto a plane (a 2D drawing view).project(curve, direction=(0, 0, -1)): Project a curve onto the body alongdirection; returns the curves on its faces.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).silhouette(direction=(0, 0, 1)): Silhouette curves on the body as seen alongdirection.thicken(thickness, *, both=False): Turn the sheet into a solid ofthickness(along the face normals; a negative thickness grows against them). Withboththe solid isthicknessthick in total, half of it to each side of the sheet.to_nurbs(): A copy whose faces and edges are all NURBS (analytic types converted).translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Face
Face(owner, kface)
A bounded piece of a surface, belonging to a body (a part, shell or sketch).
area(property):axis(property): Axis of a cylinder, cone, sphere, torus or surface of revolution.bbox(): Tight axis-aligned bounding box.center(): Area centroid. For curved faces it may lie off the face; seeinterior_point.distance_to(point):edges(seams=False): The face's edges (seam edges only withseams=True).export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).extrude(amount, **kwargs): Extrude a planar face along its normal (seeSketch.extrude).faces(): All faces of this shape.geom_type(property):"plane","cylinder","cone","sphere","torus","revolution",inner_wires():interior_point(): A point guaranteed to lie on the face.is_planar(property): True for planes and for flat B-spline faces (control points in one plane).mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).neighbors(): Faces sharing an edge with this one.normal_at(point=None): Outward unit normal at the face point closest topoint(default: the center).on(target): Place this shape, designed around the world XY plane, onto a plane or face.outer_wire():owner(property): The body this face belongs to.plane(property): The face's plane: origin at its centroid, normal pointing out of the body.radius(property): Radius of a cylinder, sphere or cone (at its base), minor radius of a torus.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).to_shell(): A sheet body holding a copy of this face.to_sketch(): A sketch holding a copy of this (planar) face.translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Edge
Edge()
A bounded curve: a line segment, an arc, a circle, an ellipse or a NURBS curve.
Edges come from bodies (part.edges()) or from curve constructors such as
smlibpy.Line, smlibpy.Arc and smlibpy.Spline.
Parameters along an edge (point_at(t)) run from 0 at the start to 1 at the end,
proportional to arc length.
arc_center(property): Center of a circular edge.bbox(): Tight axis-aligned bounding box.center(): The point halfway along the edge (usearc_centerfor a circle's center).convexity(property):"convex"for an outside corner (material angle below 180 degrees),"concave"direction(property): Unit direction of a straight edge (start to end).distance_to(point):edges(): All edges of this shape.end(property):export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.geom_type(property):"line","circle"(also arcs),"ellipse","bspline"or"other".intersections(other): Points where this edge crosses another edge.is_closed(property):is_convex(): True on an outside corner (seeconvexity).is_seam(property): True for the seam of a closed surface (an edge used twice by one face).length(property):mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).normal(property): Axis direction of a circular edge.on(target): Place this shape, designed around the world XY plane, onto a plane or face.point_at(t=0.5): Point at fractiontof the edge length (0 = start, 1 = end).radius(property): Radius of a circular edge.reversed(): The same edge traversed the other way.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).start(property):tangent_at(t=0.5): Unit tangent at fractiontof the edge length, pointing along the edge.translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Wire
Wire(edges, *, sort=True)
A chain of edges, open or closed. Wire([edge, edge, ...]) orders and orients the edges.
bbox(): Tight axis-aligned bounding box.center(): Length-weighted average of the edge midpoints.close(): This wire closed with a straight line from its end to its start.distance_to(point):edges(): All edges of this shape.end(property):export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.fillet(radius, vertices=None): Round the corners between straight edges with tangent arcs (planar wires).is_closed(property):length(property):mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).on(target): Place this shape, designed around the world XY plane, onto a plane or face.plane(): The plane of a planar wire (normal by the right-hand rule along the wire).point_at(t=0.5): Point at fractiontof the total length.reversed():rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).start(property):tangent_at(t=0.5):to_sketch(): The planar region bounded by this closed wire.translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
Vertex
Vertex(x=0.0, y=0.0, z=0.0)
A point. Vertices of bodies come from .vertices(); Vertex(x, y, z) makes one.
bbox(): Tight axis-aligned bounding box.center(): Center of mass (centroid) of the shape.distance_to(other):edges(): All edges of this shape.export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).on(target): Place this shape, designed around the world XY plane, onto a plane or face.point(property):rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).x(property):y(property):z(property):
ShapeList
ShapeList(iterable=())
A list of shapes with selection helpers.
Every selector returns a new ShapeList, so selectors chain::
part.edges().parallel_to(Z).max_by(X)
part.faces().planar().facing(-Z)
A one-element list can be used wherever a single shape is expected
(sketch.on(part.faces().top())). Use one to require exactly one.
append(object): Append object to the end of the list.at(point, tol=0.0001): Shapes passing throughpoint(vertices at, edges/faces touching it).back(): Shapes furthest along +Y.bbox():bottom(): Lowest shapes (smallest Z).center(): Average of the members' centers.circles(): Circular edges (full circles and arcs).clear(): Remove all items from list.concave(): Edges on inside corners (material angle above 180 degrees).convex(): Edges on outside corners (material angle below 180 degrees).copy(): Return a shallow copy of the list.count(value): Return number of occurrences of value.cylinders(): Cylindrical faces.edges():extend(iterable): Extend list by appending elements from the iterable.faces():facing(direction, max_angle=0.001): Faces whose outward normal points alongdirection(withinmax_angledegrees).filter(predicate): Keep the shapes for whichpredicate(shape)is true.filter_by(criterion):parallel_to(axis),of_type(name)orfilter(predicate), depending on the argument.first(property):front(): Shapes furthest along -Y.group_by(key=Axis.Z, tol=0.0001): Group shapes with equal key (withintol), groups in ascending key order.index(value, start=0, stop=9223372036854775807): Return first index of value.insert(index, object): Insert object before index.largest(): The biggest shape by volume, area or length.last(property):left(): Shapes furthest along -X.lines(): Straight edges (also straight B-spline edges, such as the edges of a chamfer).max_by(key=Axis.Z, tol=0.0001): The shapes with the largest key (all of them, if several tie).min_by(key=Axis.Z, tol=0.0001): The shapes with the smallest key (all of them, if several tie).moved(location):nearest(point): The shape whose center is closest topoint.of_type(*geom_types): Keep shapes of the given geometry types, e.g."line","circle","plane","cylinder","bspline".on(target): Every shape placed onto a plane or face (seeShape.on).one(): The only element; raises if the list does not hold exactly one shape.parallel_to(axis): Straight edges alongaxis, or planar faces whose normal is alongaxis.perpendicular_to(axis): Straight edges perpendicular toaxis, or planar faces containing it.planar(): Planar faces (also flat B-spline faces).pop(index=-1): Remove and return item at index (default last).remove(value): Remove first occurrence of value.reverse(): Reverse IN PLACE.right(): Shapes furthest along +X.rotate(axis=Axis.Z, angle=0.0):smallest(): The smallest shape by volume, area or length.smooth(): Edges where two faces meet tangentially, such as the borders of a fillet.sort(*, key=None, reverse=False): Sort the list in ascending order and return None.sort_by(key=Axis.Z, reverse=False): Sort by position along an axis, by"length"/"area"/"volume"/"radius", or by any function of a shape.sort_by_distance(point, reverse=False):top(): Highest shapes (largest Z).translate(x=0.0, y=0.0, z=0.0):vertices():wires():within(box): Shapes whose bounding box lies insidebox.
Shape
Shape()
Base class of all shapes.
bbox(): Tight axis-aligned bounding box.center(): Center of mass (centroid) of the shape.edges(): All edges of this shape.export(path, **kwargs): Write the shape to a file; the format follows the extension (step, stl, glb, ...).faces(): All faces of this shape.mesh(tolerance=None, angle=15.0): Triangulate the shape (seesmlibpy.mesh.tessellate).mirror(plane=Plane.XZ): A mirrored copy (reflection inplane, a plane or a planar face; by default the XZ plane, which flips Y).moved(location): A copy of this shape moved by a location (location * shape).on(target): Place this shape, designed around the world XY plane, onto a plane or face.rotate(axis=Axis.Z, angle=0.0): A copy rotated byangledegrees aboutaxis.scale(factor, center=(0, 0, 0)): A scaled copy.factoris a number or per-axis factors(sx, sy, sz), none of them zero (ValueError: that would flatten the shape).show(**kwargs): Show the shape in the browser viewer (seesmlibpy.show).translate(x=0.0, y=0.0, z=0.0): A copy moved by(x, y, z).vertices(): All vertices of this shape.wires(): All wires (closed edge loops of faces, or the shape itself if it is a wire).
MassProperties
MassProperties(mass, volume, area, center, inertia, density)
Mass properties of a part.
inertia is the inertia tensor about the center of mass (axes parallel to the
world axes); principal_moments and principal_axes are its eigen-decomposition.
principal_axes(property):principal_moments(property):
Geometry
Vector
Vector(*args)
An immutable 3D vector or point.
Vector(1, 2), Vector(1, 2, 3), Vector((1, 2, 3)) and Vector(other)
are all accepted. Vectors support +, -, * (by a number), /,
unary -, abs() (length), iteration and indexing.
angle_to(other): Angle to another vector in degrees (0..180).any_perpendicular(): A unit vector perpendicular to this one.cross(other):distance_to(other):dot(other):is_close(other, tol=1e-06):is_parallel(other, angle_tol=0.0001): True if both vectors point along the same line (either sense).is_perpendicular(other, angle_tol=0.0001):length(property):normalized():project_to(plane): Orthogonal projection of this point onto a plane.rotate(axis, angle): Rotate this point about an axis (through the origin for a plain vector).to_tuple():x(property):y(property):z(property):
Axis
Axis(origin=(0, 0, 0), direction=(0, 0, 1))
An infinite line through origin along direction.
Axis.X, Axis.Y and Axis.Z (also exported as X, Y, Z) are the
world axes. Axes are used to rotate, revolve, mirror, and to sort or filter shapes.
at(origin): The same direction through another point.direction(property):distance_to(point):is_parallel(other, angle_tol=0.0001):moved(loc):origin(property):position_along(point): Signed coordinate ofpointalong this axis.project(point):reversed():