Skip to main content
Participant
April 14, 2021
Answered

How to change text of a psd file ?

  • April 14, 2021
  • 1 reply
  • 1488 views

I am trying to change the text of a particular layer of psd file but I am getting following error:

Traceback (most recent call last):
File "C:\Users\deepak.prasad\Desktop\python_scrapping\psd\app4.py", line 7, in <module>
layer_facts = doc.ArtLayers["appstoreName"]
File "C:\Users\deepak.prasad\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\dynamic.py", line 240, in __getitem__
return self._get_good_object_(self._oleobj_.Invoke(dispid, LCID, invkind, 1, index))
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'No such element', None, 0, -2147352565), None)

 

Below is my code:

import win32com.client
import os

psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open(r"C:\\Users\\deepak.prasad\\Desktop\\python_scrapping\\psd\\Ad-format-final-1.psd")
doc = psApp.Application.ActiveDocument
layer_facts = doc.ArtLayers["appstoreName"]
text_of_layer = layer_facts.TextItem
text_of_layer.contents = "hello"
layer_facts.Kind = 1
text_of_layer.size = 16

This topic has been closed for replies.
Correct answer LG ludwig

Try the following assuming there is one text layer named 'appstoreName':

 

def change_text(text, layer_name):
    # Active Document Info
    # DO !!! substitute app. with psApp. in your case
    active_doc = app.ActiveDocument  
    art_layers = active_doc.ArtLayers

    for layer in art_layers:
        if layer.Name == layer_name and layer.Kind == 2:
            txt = layer.TextItem
            txt.Contents = text
            txt.Size = 16


change_text("Hello you!", "appstoreName")

 

1 reply

LG ludwig
LG ludwigCorrect answer
Inspiring
May 4, 2021

Try the following assuming there is one text layer named 'appstoreName':

 

def change_text(text, layer_name):
    # Active Document Info
    # DO !!! substitute app. with psApp. in your case
    active_doc = app.ActiveDocument  
    art_layers = active_doc.ArtLayers

    for layer in art_layers:
        if layer.Name == layer_name and layer.Kind == 2:
            txt = layer.TextItem
            txt.Contents = text
            txt.Size = 16


change_text("Hello you!", "appstoreName")