trimesh.path.exchange package

Submodules

trimesh.path.exchange.dxf module

trimesh.path.exchange.dxf.bulge_to_arcs(lines, bulge, bulge_idx, is_closed=False, metadata=None)

Polylines can have “vertex bulge,” which means the polyline has an arc tangent to segments, rather than meeting at a vertex.

From Autodesk reference: The bulge is the tangent of one fourth the included angle for an arc segment, made negative if the arc goes clockwise from the start point to the endpoint. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.

Parameters
lines(n, 2) float

Polyline vertices in order

bulge(m,) float

Vertex bulge value

bulge_idx(m,) float

Which index of lines is bulge associated with

is_closedbool

Is segment closed

metadataNone, or dict

Entity metadata to add

Returns
vertices(a, 2) float

New vertices for poly-arc

entities(b,) entities.Entity

New entities, either line or arc

trimesh.path.exchange.dxf.export_dxf(path, layers=None)

Export a 2D path object to a DXF file

Parameters
path: trimesh.path.path.Path2D
Returns
export: str, path formatted as a DXF file
trimesh.path.exchange.dxf.get_key(blob, field, code)

Given a loaded (n, 2) blob and a field name get a value by code.

trimesh.path.exchange.dxf.load_dwg(file_obj, **kwargs)

Load DWG files by converting them to DXF files using TeighaFileConverter.

Parameters
file_objfile- like object
Returns
loadeddict

kwargs for a Path2D constructor

trimesh.path.exchange.dxf.load_dxf(file_obj, **kwargs)

Load a DXF file to a dictionary containing vertices and entities.

Parameters
file_obj: file or file- like object (has object.read method)
Returns
result: dict, keys are entities, vertices and metadata

trimesh.path.exchange.export module

trimesh.path.exchange.export.export_dict(path)

Export a path as a dict of kwargs for the Path constructor.

trimesh.path.exchange.export.export_path(path, file_type=None, file_obj=None, **kwargs)

Export a Path object to a file- like object, or to a filename

file_obj: None, str, or file object

A filename string or a file-like object

file_type: None or str

File type, e.g.: ‘svg’, ‘dxf’

kwargs : passed to loader

Returns
exportedstr or bytes

Data exported

trimesh.path.exchange.load module

trimesh.path.exchange.load.load_path(obj, file_type=None, **kwargs)

Load a file to a Path object.

Parameters
objOne of the following:
  • Path, Path2D, or Path3D objects

  • open file object (dxf or svg)

  • file name (dxf or svg)

  • shapely.geometry.Polygon

  • shapely.geometry.MultiLineString

  • dict with kwargs for Path constructor

  • (n,2,(2|3)) float, line segments

file_typestr

Type of file is required if file object passed.

Returns
pathPath, Path2D, Path3D object

Data as a native trimesh Path object

trimesh.path.exchange.load.path_formats()

Get a list of supported path formats.

Returns
loaderslist of str

Extensions of loadable formats, ie: [‘svg’, ‘dxf’]

trimesh.path.exchange.misc module

trimesh.path.exchange.misc.dict_to_path(as_dict)

Turn a pure dict into a dict containing entity objects that can be sent directly to a Path constructor.

Parameters
as_dictdict

Has keys: ‘vertices’, ‘entities’

Returns
kwargsdict

Has keys: ‘vertices’, ‘entities’

trimesh.path.exchange.misc.edges_to_path(edges, vertices, **kwargs)

Given an edge list of indices and associated vertices representing lines, generate kwargs for a Path object.

Parameters
edges(n, 2) int

Vertex indices of line segments

vertices(m, dimension) float

Vertex positions where dimension is 2 or 3

Returns
kwargs: dict, kwargs for Path constructor
trimesh.path.exchange.misc.faces_to_path(mesh, face_ids=None, **kwargs)

Given a mesh and face indices find the outline edges and turn them into a Path3D.

meshtrimesh.Trimesh

Triangulated surface in 3D

face_ids(n,) int

Indexes referencing mesh.faces

Returns
kwargsdict

Kwargs for Path3D constructor

trimesh.path.exchange.misc.lines_to_path(lines)

Turn line segments into a Path2D or Path3D object.

Parameters
lines(n, 2, dimension) or (n, dimension) float

Line segments or connected polyline curve in 2D or 3D

Returns
kwargsdict

kwargs for Path constructor

trimesh.path.exchange.misc.linestrings_to_path(multi)

Load shapely LineString objects into a trimesh.path.Path2D object

Parameters
multishapely.geometry.LineString or MultiLineString

Input 2D geometry

Returns
kwargsdict

Keyword arguments for Path2D constructor

trimesh.path.exchange.misc.polygon_to_path(polygon)

Load shapely Polygon objects into a trimesh.path.Path2D object

Parameters
polygonshapely.geometry.Polygon

Input geometry

Returns
kwargsdict

Keyword arguments for Path2D constructor

trimesh.path.exchange.svg_io module

trimesh.path.exchange.svg_io.export_svg(drawing, return_path=False, layers=None, **kwargs)

Export a Path2D object into an SVG file.

Parameters
drawingPath2D

Source geometry

return_pathbool

If True return only path string

layersNone, or [str]

Only export specified layers

Returns
as_svg: str, XML formatted as SVG
trimesh.path.exchange.svg_io.svg_to_path(file_obj, file_type=None)

Load an SVG file into a Path2D object.

Parameters
file_objopen file object

Contains SVG data

file_type: None

Not used

Returns
loadeddict

With kwargs for Path2D constructor

trimesh.path.exchange.svg_io.transform_to_matrices(transform)

Convert an SVG transform string to an array of matrices.

> transform = “rotate(-10 50 100)

translate(-36 45.5) skewX(40) scale(1 0.5)”

Parameters
transformstr

Contains transformation information in SVG form

Returns
matrices(n, 3, 3) float

Multiple transformation matrices from input transform string

Module contents