def virtual_entities(entity: AnyText, kind: int = Kind.HATCHES) -> EntityQuery: """Convert the text content of DXF entities TEXT and ATTRIB into virtual SPLINE and 3D POLYLINE entities or approximated LWPOLYLINE entities as outlines, or as HATCH entities as fillings. Returns the virtual DXF entities as an :class:`~ezdxf.query.EntityQuery` object. Args: entity: TEXT or ATTRIB entity kind: kind of entities to create as bit flags, see enum :class:`Kind` """ check_entity_type(entity) extrusion = entity.dxf.extrusion attribs = entity.graphic_properties() entities: List[DXFGraphic] = [] if kind & Kind.HATCHES: entities.extend(make_hatches_from_entity(entity)) if kind & (Kind.SPLINES + Kind.LWPOLYLINES): paths = make_paths_from_entity(entity) if kind & Kind.SPLINES: entities.extend( path.to_splines_and_polylines(paths, dxfattribs=attribs)) if kind & Kind.LWPOLYLINES: entities.extend( path.to_lwpolylines(paths, extrusion=extrusion, dxfattribs=attribs)) return EntityQuery(entities)
def test_to_splines_and_polylines(self, path): entities = list(to_splines_and_polylines([path])) assert len(entities) == 2 polyline = entities[0] spline = entities[1] assert polyline.dxftype() == "POLYLINE" assert spline.dxftype() == "SPLINE" assert polyline.vertices[0].dxf.location.isclose((0, 0)) assert polyline.vertices[1].dxf.location.isclose((4, 0)) assert close_vectors( Vec3.generate(spline.control_points), [(4, 0, 0), (3, 1, 1), (1, 1, 1), (0, 0, 0)], )
def test_to_splines_and_polylines(self, path): entities = list(to_splines_and_polylines([path])) assert len(entities) == 2 polyline = entities[0] spline = entities[1] assert polyline.dxftype() == 'POLYLINE' assert spline.dxftype() == 'SPLINE' assert polyline.vertices[0].dxf.location == (0, 0) assert polyline.vertices[1].dxf.location == (4, 0) assert spline.control_points[0] == Vec3(4, 0, 0) assert spline.control_points[1] == Vec3(3, 1, 1) # 3D entity assert spline.control_points[2] == Vec3(1, 1, 1) # 3D entity assert spline.control_points[3] == Vec3(0, 0, 0)