爱生活,乐分享,大家好才是真的好!
返回顶部

ezdxf写CAD文本用自定义字体

ezdxf写CAD文本用自定义字体

自定义字体

 
 
 
x
 
 
 
 
import ezdxf

doc = ezdxf.new('R12')
msp = doc.modelspace()

doc.styles.new('custom_style', dxfattribs={'font': 'myFont.ttf'})

text_to_export = ex.text_to_export.text()

msp.add_text(text_to_export,
             dxfattribs={
                  'style': "custom_style",
                  'height': 0.35}
             ).set_pos((2, 6), align='LEFT')

doc.saveas("text.dxf")
 

注意:1,千万不能在ezdxf.new()时用setup=True属性。该属性只为系统标准字体,否则圆、多段线等其他对象。

2,注意自定义字体的路径。到c:\windows\fonts寻找,复制到项目路径下。

标准字体

 
 
 
xxxxxxxxxx
 
 
 
 
import ezdxf
from ezdxf.enums import TextEntityAlignment
 
doc = ezdxf.new("R12", setup=True)
msp = doc.modelspace()
 
msp.add_text("A Simple Text").set_placement(
    (2, 3),
    align=TextEntityAlignment.MIDDLE_RIGHT
)

# Using a predefined text style:
msp.add_text(
    "Text Style Example: Liberation Serif",
    height=0.35,
    dxfattribs={"style": "LiberationSerif"}
).set_placement((2, 6), align=TextEntityAlignment.LEFT)

doc.saveas("simple_text.dxf")
 

注意:1,参考官网:通过参数Setup =True设置一些标准的文本样式和线型:(Setup some standard text styles and linetypes by argument setup=True:)链接:https://ezdxf.readthedocs.io/en/stable/tutorials/text.html#tutorial-for-text

2,其他字体样式(某字体样式的文本,就是该字体样式)也参考官网,直接替换就可以了。

 

posted @ 2024-04-12 19:25  博观约取&厚积薄发  阅读(53)  评论(0编辑  收藏  举报
回到顶部
返回顶部