trimesh.path.exchange package

Submodules

trimesh.path.exchange.dxf module

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_obj : file- like object
Returns:
loaded : dict

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:
exported : str 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:
obj : One 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_type : str

Type of file is required if file object passed.

Returns:
path : Path, Path2D, Path3D object

Data as a native trimesh Path object

trimesh.path.exchange.load.path_formats()

Get a list of supported path formats.

Returns:
loaders : list 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_dict : dict

Has keys: ‘vertices’, ‘entities’

Returns:
kwargs : dict

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.

mesh : trimesh.Trimesh
Triangulated surface in 3D
face_ids : (n,) int
Indexes referencing mesh.faces
Returns:
kwargs : dict

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:
kwargs : dict

kwargs for Path constructor

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

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

Parameters:
multi : shapely.geometry.LineString or MultiLineString

Input 2D geometry

Returns:
kwargs : dict

Keyword arguments for Path2D constructor

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

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

Parameters:
polygon : shapely.geometry.Polygon

Input geometry

Returns:
kwargs : dict

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:
drawing : Path2D

Source geometry

return_path : bool

If True return only path string

layers : None, 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_obj: open file object
file_type: unused
Returns:
loaded: dict with kwargs for Path2D constructor

Module contents