我需要在镜像的 DXF 绘图中写入文本。我使用 python 和 ezdxf 模块。根据文档,需要设置一些标志,但我总是收到 DXFAttributeError。
我尝试使用 'text_ Generation_flags': 2 和 'text_direction': (-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)
使用哪个标志以及如何以正确的方式设置它?
最佳答案
我没有使用过 ezdxf,但 text_direction
是 MTEXT
实体(DXF 组 11)的属性,并且是有效控制旋转的另一种方法多行文字。
要镜像单行 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')
关于python - 如何用 'ezdxf' 写入镜像文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55377283/