from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers import TextLayer
from aspose.psd import Color
from aspose.pycore import cast
psdFilePath = “template.psd”
def main():
source_file = psdFilePath
output_file = “Output.psd”
with PsdImage.load(source_file) as img:
image = cast(PsdImage, img)
text_layer = None
# Define a recursive function to find TextLayer
def find_text_layer(layers):
for i, layer in enumerate(layers):
print(f"Checking layer {i}: {layer}")
if isinstance(layer, TextLayer):
return cast(TextLayer, layer)
elif hasattr(layer, 'layers'):
text_layer = find_text_layer(layer.layers)
if text_layer:
return text_layer
return None
text_layer = find_text_layer(image.layers)
if text_layer:
text_layer.update_text("Update", Color.red)
image.save(output_file)
else:
print("Text layer not found.")
if name == ‘main’:
main()
Thats my code, just a simple program to find a text layer, unfortunaly it always returns text layer not found on my test psd that 100% includes text layers. Any ideas? Mac os sequoia 15.0.1, latest aspose version