Example #1
0
def lwpolyline():
    pline = LWPolyline.new(dxfattribs={
        "elevation": 4,
        "extrusion": (0, 0, -1),
    })
    pline.set_points(POLYLINE_POINTS)
    return pline
Example #2
0
def to_lwpolylines(
    paths: Iterable[Path],
    *,
    distance: float = MAX_DISTANCE,
    segments: int = MIN_SEGMENTS,
    extrusion: "Vertex" = Z_AXIS,
    dxfattribs=None,
) -> Iterable[LWPolyline]:
    """Convert the given `paths` into :class:`~ezdxf.entities.LWPolyline`
    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 :class:`~ezdxf.entities.LWPolyline` 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"] = elevation
        dxfattribs["extrusion"] = extrusion
    elif reference_point.z != 0:
        dxfattribs["elevation"] = reference_point.z

    for path in tools.single_paths(paths):
        if len(path) > 0:
            p = LWPolyline.new(dxfattribs=dxfattribs)
            p.append_points(path.flattening(distance, segments), format="xy")
            yield p
def lwpolyline1():
    e = LWPolyline.new(dxfattribs={
        "layer": "0",
        "linetype": "Continuous",
        "color": 0,
        "flags": 0,
        "const_width": 0.0,
        "elevation": 2.999999999999999e99,
        "extrusion": (0.0, 0.0, 1.0),
    }, )
    e.set_points([
        (297888, 108770, 0.0, 0.0, 0.0512534542487669),
        (297930, 108335, 0.0, 0.0, 0.0),
    ])
    return e
def lwpolyline() -> LWPolyline:
    # Issue 414 shows an error in the bounding box calculation for a closed
    # LWPOLYLINE representing a filled circle (const_width=0.45) and an
    # inverted extrusion (0, 0, -1).
    #
    # original data of the LWPOLYLINE:
    # [
    #     (-43710.28841108403, 19138.631023711587, 0.0, 0.0, -1.0),
    #     (-43710.28841108403, 19139.079023711445, 0.0, 0.0, -1.0),
    # ]
    # simplified test data:
    points = [(-10.0, 1.0, 0.0, 0.0, -1.0), (-10.0, 1.45, 0.0, 0.0, -1.0)]
    pline = LWPolyline.new(dxfattribs={
        "extrusion": (0, 0, -1),
        "const_width": 0.45
    })
    pline.append_points(points)
    pline.close()
    return pline