我需要用镜像的DXF绘图来写文本。我使用python和ezdxf模块。根据docs,有一些标志需要设置,但我总是得到DXFAttributeError。
我尝试使用文本_生成_标志:2和‘文本_方向’:(-1,0,0)
下面是我的代码(在没有镜像尝试的情况下工作得很好)
def publish_face_no_bolts(poly, label, filename):
t = poly.get_default_transformation()
trans_poly = poly.transform(t)
# trans_poly = trans_poly.make_coordinates_positive()
points = transformation.points_3d_to_2d(trans_poly.poly_points)
points.append(points[0]) # must close polygon
drawing = ezdxf.new(dxfversion='AC1024') # or use the AutoCAD release name ezdxf.new(dxfversion='R2010')
modelspace = drawing.modelspace()
modelspace.add_lwpolyline(points, dxfattribs={'color': 7})
drawing.layers.new('TEXTLAYER', dxfattribs={'color': 1})
# use set_pos() for proper TEXT alignment - the relations between halign, valign, insert and align_point are tricky.
# drawing.styles.new('mirrored', dxfattribs={'text_generation_flags': 2})
# 'text_direction': (0, 1, 0), # write in y direction
drawing.styles.new('mirrored', dxfattribs={ 'text_direction': (-1, 0, 0)})
err, cx, cy = polygon.centroid2d(points)
modelspace.add_text(label, dxfattribs={'layer': 'TEXTLAYER', 'text_direction': (-1, 0, 0), 'height': 4}).set_pos((cx, cy), align='CENTER')
drawing.saveas(filename)使用哪个标志,以及如何正确设置它?
发布于 2019-03-27 23:16:10
我没有使用ezdxf,但是text_direction是MTEXT实体(DXF组11)的一个属性,也是有效控制MText旋转的另一种方法。
要镜像一个单行TEXT实体,您需要将DXF组71设置为2,在简要查看了ezdxf的代码之后,它看起来将作为text_generation_flag参数来实现。
因此,我建议:
modelspace.add_text(label, dxfattribs={'layer': 'TEXTLAYER', 'text_generation_flag': 2, 'height': 4}).set_pos((cx, cy), align='CENTER')https://stackoverflow.com/questions/55377283
复制相似问题