Get Content From DXF Entities
从 DXF 实体获取内容
TEXT Entity 文本实体
The content of the TEXT entity is stored in a single DXF attribute Text.dxf.text
and has an empty string as default value:
TEXT 实体的内容存储在单个 DXF 属性 Text.dxf.text
中,默认值为空字符串:
for text in msp.query("TEXT"):
print(text.dxf.text)
The plain_text()
method returns the content of the TEXT
entity without formatting codes.
plain_text()
方法返回不带格式代码的 TEXT 实体内容。
MTEXT Entity 多行文字实体
The content of the MTEXT entity is stored in multiple DXF attributes. The content can be
accessed by the read/write property text
and the DXF attribute
MText.dxf.text
and has an empty string as default value:
MTEXT 实体的内容存储于多个 DXF 属性中,可通过读写属性 text
和 DXF 属性 MText.dxf.text
访问,默认值为空字符串:
for mtext in msp.query("MTEXT"):
print(mtext.text)
# is the same as:
print(mtext.dxf.text)
Important 重要
The line ending character \n
will be replaced automatically by the MTEXT line
ending \P
.
换行符 \n
会被自动替换为 MTEXT 换行符 \P
。
The plain_text()
method returns the content of the MTEXT
entity without inline formatting codes.
plain_text()
方法返回不含内联格式代码的 MTEXT 实体内容。
See also 另请参阅
Classes 类
Tutorials 教程
MLEADER Entity MLEADER 实体
The content of MLEADER entities is stored in the MultiLeader.context
object.
The MLEADER contains text content if the context.mtext
attribute is not None
and block content if the context.block
attribute is not None
MLEADER 实体的内容存储在 MultiLeader.context
对象中。若 context.mtext
属性不为 None
,则 MLEADER 包含文本内容;若 context.block
属性不为 None
,则包含块内容。
See also 另请参阅
Classes 类
Tutorials 教程
Text Content 文本内容
for mleader in msp.query("MLEADER MULTILEADER"):
mtext = mleader.context.mtext
if mtext:
print(mtext.insert) # insert location
print(mtext.default_content) # text content
The text content supports the same formatting features as the MTEXT entity.
文本内容支持与 MTEXT 实体相同的格式特性。
Block Content 块内容
The INSERT (block reference) attributes are stored in MultiLeader.context.block
as BlockData
.
INSERT(块引用)的属性以 BlockData
的形式存储在 MultiLeader.context.block
中。
for mleader in msp.query("MLEADER MULTILEADER"):
block = mleader.context.block
if block:
print(block.insert) # insert location
The ATTRIB attributes are stored outside the context object in MultiLeader.block_attribs
as AttribData
.
ATTRIB 属性存储在上下文对象之外,在 MultiLeader.block_attribs
中以 AttribData
的形式存在。
for mleader in msp.query("MLEADER MULTILEADER"):
for attrib in mleader.block_attribs:
print(attrib.text) # text content of the ATTRIB entity
DIMENSION Entity 尺寸标注实体
Get real measurement determined by definition points:
获取由定义点确定的实际测量值:
for dimension in msp.query("DIMENSION"):
print(str(dimension))
print(f"Dimension Type: {dimension.dimtype}")
print(f"Measurement: {dimension.get_measurement()}")
Type 类型 |
Dimension Type 标注类型 |
Measurement 测量值 |
---|---|---|
0 |
Linear and Rotated Dimension |
length in drawing units 绘图单位长度 |
1 |
Aligned Dimension 对齐标注 |
length in drawing units 绘图单位长度 |
2 |
Angular Dimension 角度标注 |
angle in degree 角度(度) |
3 |
Diameter Dimension 直径标注 |
length in drawing units 绘图单位长度 |
4 |
Radius Dimension 半径标注 |
length in drawing units 绘图单位长度 |
5 |
Angular 3P Dimension 三点角度标注 |
angle in degree 角度(度) |
6 |
Ordinate Dimension 坐标标注 |
feature location as |
Get measurement text. This is how the measurement text was rendered into the associated
geometry block by the CAD application as the DIMENSION entity was created:
获取测量文本。这是 CAD 应用程序在创建 DIMENSION 实体时如何将测量文本渲染到关联的几何块中的:
for dimension in msp.query("DIMENSION"):
print(str(dimension))
print(f"Measurement Text: {dimension.dxf.text}")
Text 文本 |
Measurement text rendered by CAD application |
---|---|
|
actual measurement 实际测量值 |
|
(empty string) actual measurement |
|
(space) measurement text is suppressed |
other 其他 |
measurement text entered by the CAD user |
Get measurement text from text entities in the associated geometry block. This is the
actual measurement text displayed by CAD applications:
从关联几何块中的文本实体获取测量文本。这是 CAD 应用程序实际显示的测量文本:
for dimension in msp.query("DIMENSION"):
print(str(dimension))
block = dimension.get_geometry_block()
if block is None:
print("Geometry block not found.")
continue
for entity in block.query("TEXT MTEXT"):
print(f"{str(entity)}: {entity.dxf.text}")
See also 另请参阅
Tutorials: 教程:
Classes: 类:
ACAD_TABLE Entity ACAD_TABLE 实体
The helper function read_acad_table_content()
returns the content of an ACAD_TABLE
entity as list of table rows. If the count of table rows or table columns is missing the
complete content is stored in the first row. All cells contain strings.
辅助函数 read_acad_table_content()
以表格行列表形式返回 ACAD_TABLE 实体的内容。若表格行数或列数缺失,则完整内容会存储在第一行中。所有单元格均包含字符串。
from ezdxf.entities.acad_table import read_acad_table_content
...
for acad_table in msp.query("ACAD_TABLE"):
content = read_acad_table_content(acad_table)
for n, row in enumerate(content):
for m, value in enumerate(row):
print(f"cell [{n}, {m}] = '{value}'")
Important 重要
The ACAD_TABLE entity has only limited support to preserve the entity. There is no
support for adding a new ACAD_TABLE entity or modifying it’s content.
ACAD_TABLE 实体仅具备有限的实体保留支持,不支持添加新的 ACAD_TABLE 实体或修改其内容。
INSERT Entity - Block References
INSERT 实体 - 块引用
Get Block Attributes 获取块属性
Get a block attribute by tag:
通过标签获取块属性:
diameter = insert.get_attrib('diameter')
if diameter is not None:
print(f"diameter = {diameter.dxf.text}")
Iterate over all block attributes:
遍历所有块属性:
for attrib in insert.attribs:
print(f"{attrib.dxf.tag} = {attrib.dxf.text}")
Important 重要
Do not confuse block attributes and DXF entity attributes, these are different
concepts!
请勿混淆块属性和 DXF 实体属性,这是两个不同的概念!
Get Block Entities 获取块实体
Get block entities as virtual DXF entities from an Insert
entity:
从 Insert
实体中获取虚拟 DXF 块实体:
for insert in msp.query("INSERT"):
for entity in insert.virtual_entities():
print(str(entity))
Get Transformation Matrix
获取变换矩阵
m = insert.matrix44()
This transformation matrix transforms the virtual block entities from the block reference
coordinate system into the WCS.
此变换矩阵将虚拟块实体从块参照坐标系转换至世界坐标系(WCS)。
See also 另请参阅
Tasks: 任务:
Tutorials: 教程:
Basics: 基础:
Classes: 类: