python - 如何用 'ezdxf' 写入镜像文本?

标签 python dxf

我需要在镜像的 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_directionMTEXT 实体(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/

相关文章:

geometry - 弧变换起点终点到起点角度终点角度

java - 用Java生成DXF绘图

python-3.x - 如何使用 ezdxf 编辑 AutoCAD 图层描述

python - .svg 到 .dxf(使用 Inkscape?)

delphi - 从 Delphi 应用程序将文本样式写入 DXF

python - 导航标题没有很好地对齐并且导航栏有点太粗了?

python - 在 python 中自动化 IE、MS-Office 设置验证的最佳方法

python - Keras LSTM 层中的 4D 输入

Python 等价于 Ruby Array.each 方法

python - 在数据帧中复制行 x 次 - 提高性能