텍스트 작업
Contents
[
Hide
]텍스트 작업
거의 모든 도면에는 텍스트 객체가 포함되어 있으며, 이 예제는 텍스트 객체로 작업하는 방법을 보여줍니다. DWG/DXF에서 텍스트를 저장할 수 있는 다양한 유형의 객체가 있으며, 이들은 CadText, CadMText, CadAttDef, CadAttrib입니다. 마지막 두 유형은 일반적으로 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) |