Skip to main content
Known Participant
July 28, 2018
Question

python photoshop scripting creating a text layer

  • July 28, 2018
  • 3 replies
  • 8620 views

Hi i have this on my python script

import win32com.client


psApp = win32com.client.Dispatch("Photoshop.Application")


psApp.Open(r"C:\Users\Kim-DEV\psd_env\psdtest.psd"

doc = psApp.Application.ActiveDocument

layerRef = doc.ArtLayers.Add()

layerRef.Kind = 2

after i run the script i get error on layerRef.Kind = 2

it says that

Traceback (most recent call last):

  File "C:\Users\Kim-DEV\psd_env\psd.py", line 8, in <module>

    layerRef.Kind = 2

  File "C:\Users\Kim-DEV\psd_env\lib\site-packages\win32com\client\dynamic.py", line 565, in __setattr__

    self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', '', None, 0, -2147213322), None)

can anyone tell me how to fix this ?

This topic has been closed for replies.

3 replies

Hal.long
Participant
May 29, 2020

Hey,

 

Maybe you can try to use the python API for photoshop.

 

 https://github.com/loonghao/photoshop-python-api

 

The docs:

https://photoshop-python-api.readthedocs.io/en/master/

 

Cheers,

Kukurykus
Legend
July 28, 2018

You can't set layer kind this way, only check its kind. From empty layers you can create only text layers. Say what kind is 2?

Known Participant
July 28, 2018

i wanted to create text layers. and 2 value is a psTextLayer

Kukurykus
Legend
July 28, 2018

Like I said I don't think you can set new artLayer to the kind, even if it's textLayer. It won't change its kind. You have to use appropriate command textLayer was created. Anyway if you remove last line from you code will it create at least artLayer?

Known Participant
July 28, 2018

layerRef.Kind = 1 works..

but 2 above i get already errors same on that one.