我需要在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)
要使用哪个标志以及如何以正确的方式设置它?
答案 0 :(得分:0)
我没有使用过ezdxf,但是text_direction
是MTEXT
实体(DXF组11)的属性,并且是有效控制MText旋转的另一种方式。
要镜像单行TEXT
实体,您需要将DXF组71设置为2,在简要查看ezdxf的代码后,它看起来将实现为{{1} }参数。
因此,我建议:
text_generation_flag