Mit Text arbeiten

Mit Text arbeiten

Fast alle Zeichnungen enthalten Textobjekte, und diese Beispiele zeigen, wie man Operationen mit ihnen durchführt. Es gibt verschiedene Arten von Entitäten für DWG/DXF, die Text speichern können, nämlich CadText, CadMText, CadAttDef, CadAttrib. Die letzten beiden Typen sind typischerweise mit CadInsertObject verbunden und werden innerhalb davon oder im entsprechenden Block gespeichert.

Hier sind einige Beispiele, die Operationen mit Text beschreiben.

Text suchen

Dieses Beispiel zeigt, wie man Textwerte in der DWG/DXF-Datei findet und kann auch zum Ersetzen von Textwerten verwendet werden.

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)