テキストの操作
Contents
[
Hide
]テキストの操作
ほとんどすべての図面にはテキストオブジェクトが含まれており、これらの例はそれらを操作する方法を示しています。 DWG/DXFにはテキストを保存できる異なるタイプのエンティティがあり、CadText、CadMText、CadAttDef、CadAttribの4つがあります。最後の2つのタイプは通常、CadInsertObjectに関連しており、それに内部または対応するブロック内に保存されます。
以下は、テキストに関する操作を説明するいくつかの例です。
テキストの検索
この例は、DWG/DXFファイル内のテキスト値を見つける方法を示しており、テキスト値の置き換えにも使用できます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.cad as cad | |
from aspose.pycore import cast | |
if __name__ == '__main__': | |
image = cad.fileformats.cad.CadImage.load(file) | |
castedImage = cast(cad.fileformats.cad.CadImage, image) | |
for entity in castedImage.entities: | |
if entity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.TEXT: | |
text = cast(cad.fileformats.cad.cadobjects.CadText, entity) | |
print(text.default_value) | |
if entity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.MTEXT: | |
mtext = cast(cad.fileformats.cad.cadobjects.CadMText, entity) | |
print(mtext.full_clear_text) | |
if entity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.ATTRIB: | |
attrib = cast(cad.fileformats.cad.cadobjects.attentities.CadAttrib, entity) | |
print(attrib.default_text) | |
if entity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.ATTDEF: | |
attDef = cast(cad.fileformats.cad.cadobjects.attentities.CadAttDef, entity) | |
print(attDef.definition_tag_string) | |
if entity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.INSERT: | |
insert = cast(cad.fileformats.cad.cadobjects.CadInsertObject, entity) | |
for block in castedImage.block_entities.values: | |
if block.original_block_name == insert.name: | |
for blockEntity in block.entities: | |
if blockEntity.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.ATTDEF: | |
attDef = cast(cad.fileformats.cad.cadobjects.attentities.CadAttDef, blockEntity) | |
print(attDef.prompt_string) | |
for e in insert.child_objects: | |
if e.type_name == cad.fileformats.cad.cadconsts.CadEntityTypeName.ATTRIB: | |
attrib = cast(cad.fileformats.cad.cadobjects.attentities.CadAttrib, e) | |
print(attrib.definition_tag_string) |