butterfly.stl.types module

class butterfly.stl.types.Facet(normal, vertices, attributes=None)[source]

Bases: object

A facet (triangle) from a stl.Solid.

a

The length the side of the facet between vertices[0] and vertices[1].

area

The surface area of the facet, as computed by Heron’s Formula.

attributes = None

Raw binary attribute bytes. According to the STL spec these are unused and thus this should always be empty, but some modeling software encodes non-standard data in here which callers may wish to access.

At present these attribute bytes are populated only when reading binary STL files (since ASCII STL files have no place for this data) and they are ignored when writing a binary STL file, so round-tripping a file through this library will lose the non-standard attribute data.

b

The length of the side of the facet between vertices[0] and vertices[2].

c

The length of the side of the facet between vertices[1] and vertices[2].

normal = None

The ‘normal’ vector of the facet, as a stl.Vector3d.

perimeter

The length of the perimeter of the facet.

vertices = None

3-element sequence of stl.Vector3d representing the facet’s three vertices, in order.

class butterfly.stl.types.Solid(name=None, facets=None)[source]

Bases: object

A solid object; the root element of an STL file.

add_facet(*args, **kwargs)[source]

Append a new facet to the object.

Takes the same arguments as the stl.Facet type.

facets = []

list of stl.Facet objects representing the facets (triangles) that make up the exterior surface of this object.

name = None

The name given to the object by the STL file header.

normals

Get facet normals.

surface_area

The sum of the areas of all facets in the object.

vertices

Unique vertices for all facets.

write_ascii(file)[source]

Write this object to a file in STL ascii format.

file must be a file-like object (supporting a write method), to which the data will be written.

write_binary(file)[source]

Write this object to a file in STL binary format.

file must be a file-like object (supporting a write method), to which the data will be written.

class butterfly.stl.types.Vector3d(x, y, z)[source]

Bases: tuple

Three-dimensional vector.

Used to represent both normals and vertices of stl.Facet objects.

This is a subtype of tuple, so can also be treated like a three-element tuple in (x, y, z) order.

x

The X value of the vector.

which most applications interpret as the left-right axis.

y

The Y value of the vector.

which most applications interpret as the in-out axis.

z

The Z value of the vector.

which most applications interpret as the up-down axis.