• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to change text of a psd file ?

New Here ,
Apr 14, 2021 Apr 14, 2021

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting , Windows

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , May 04, 2021 May 04, 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")

 

Votes

Translate

Translate
Adobe
Community Beginner ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

LATEST

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")

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines