def to_polylines3d(paths: Iterable[Path], *, distance: float = MAX_DISTANCE, segments: int = MIN_SEGMENTS, dxfattribs: Optional[Dict] = None) -> Iterable[Polyline]: """ Convert the given `paths` into 3D :class:`~ezdxf.entities.Polyline` entities. Args: paths: iterable of :class:`Path` objects distance: maximum distance, see :meth:`Path.flattening` segments: minimum segment count per Bézier curve dxfattribs: additional DXF attribs Returns: iterable of 3D :class:`~ezdxf.entities.Polyline` objects .. versionadded:: 0.16 """ if isinstance(paths, Path): paths = [paths] dxfattribs = dxfattribs or {} dxfattribs['flags'] = const.POLYLINE_3D_POLYLINE for path in paths: p = Polyline.new(dxfattribs=dxfattribs) p.append_vertices(path.flattening(distance, segments)) yield p
def test_3d_polyline(): from ezdxf.entities import Polyline pline = Polyline.new(dxfattribs={'flags': Polyline.POLYLINE_3D}) pline.append_vertices([(1, 1, 1), (2, 1, 3), (2, 2, 2)]) path = make_path(pline) assert path.start == (1, 1, 1) assert path.end == (2, 2, 2) assert len(path) == 2
def to_polylines2d( paths: Iterable[Path], *, distance: float = MAX_DISTANCE, segments: int = MIN_SEGMENTS, extrusion: "Vertex" = Z_AXIS, dxfattribs=None, ) -> Iterable[Polyline]: """Convert the given `paths` into 2D :class:`~ezdxf.entities.Polyline` entities. The `extrusion` vector is applied to all paths, all vertices are projected onto the plane normal to this extrusion vector. The default extrusion vector is the WCS z-axis. The plane elevation is the distance from the WCS origin to the start point of the first path. Args: paths: iterable of :class:`Path` objects distance: maximum distance, see :meth:`Path.flattening` segments: minimum segment count per Bézier curve extrusion: extrusion vector for all paths dxfattribs: additional DXF attribs Returns: iterable of 2D :class:`~ezdxf.entities.Polyline` objects .. versionadded:: 0.16 """ if isinstance(paths, Path): paths = [paths] else: paths = list(paths) if len(paths) == 0: return [] extrusion = Vec3(extrusion) reference_point = paths[0].start dxfattribs = dict(dxfattribs or {}) if not Z_AXIS.isclose(extrusion): ocs, elevation = _get_ocs(extrusion, reference_point) paths = tools.transform_paths_to_ocs(paths, ocs) dxfattribs["elevation"] = Vec3(0, 0, elevation) dxfattribs["extrusion"] = extrusion elif reference_point.z != 0: dxfattribs["elevation"] = Vec3(0, 0, reference_point.z) for path in tools.single_paths(paths): if len(path) > 0: p = Polyline.new(dxfattribs=dxfattribs) p.append_vertices(path.flattening(distance, segments)) yield p
def to_splines_and_polylines( paths: Iterable[Path], *, g1_tol: float = G1_TOL, dxfattribs: Optional[Dict] = None ) -> Iterable[Union[Spline, Polyline]]: """ Convert the given `paths` into :class:`~ezdxf.entities.Spline` and 3D :class:`~ezdxf.entities.Polyline` entities. Args: paths: iterable of :class:`Path` objects g1_tol: tolerance for G1 continuity check dxfattribs: additional DXF attribs Returns: iterable of :class:`~ezdxf.entities.Line` objects .. versionadded:: 0.16 """ if isinstance(paths, Path): paths = [paths] dxfattribs = dxfattribs or {} for path in paths: for data in to_bsplines_and_vertices(path, g1_tol): if isinstance(data, BSpline): spline = Spline.new(dxfattribs=dxfattribs) spline.apply_construction_tool(data) yield spline else: attribs = dict(dxfattribs) attribs['flags'] = const.POLYLINE_3D_POLYLINE polyline = Polyline.new(dxfattribs=dxfattribs) polyline.append_vertices(data) yield polyline