Cross posting from tech-artists in hopes of getting something so I can start working on this
![:( :(](https://polycount.com/plugins/emojiextender/emoji/twitter/frown.png)
Anywho, following Adam's blog post (
http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html) about COM and python and for some reason the code breaks at the open stage. Here's the code:
import win32com.client
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open(r"C:\test.jpg")
doc = psApp.Application.ActiveDocument
layer = doc.ArtLayers[0]
layer.AdjustBrightnessContrast(20,-15)
doc.Save()
pretty much a copy and paste and I get this as an error
Traceback (most recent call last):
File "C:\Users\Alistair Braz\workspace\Test\test.py", line 3, in <module>
psApp.Open(r"C:\test.jpg")
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 505, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Adobe Photoshop', u'Illegal argument - argument 1\n- Required value is missing', None, 0, -2147220262), None)
Any ideas? I thought it was 2.7 been weird so moved to 2.6 and still nothing. Installed 2.6 pywin and getting same thing. Photoshop is 64bit and I installed the 64bit version of pywin too.
Replies
I just ran this:
And it worked! Sweet!
The psd already existed before running the script.
I'm using Photoshop CS2, 32bit Python 2.6.6, and pywin32-216.win32-py2.6.exe from here.
I ran the script from within my IDE (spyder).
Good luck, and thanks for getting me off my ass to actually try this. I always wondered if it would work.
EDIT:
I just checked to make sure that script works on it's own without spyder, and it does, so that's not what's causing your problem.
It looks like a read error to me, but I'm just guessing. Does the file you are trying to open exist already? and do you have read/write permissions on that drive?
EDIT2:
Just tested with a JPG, that worked too, so that's not it either.
EDIT3:
Yup tested with the file missing and got this:
So that might possibly be your problem, maybe...
The file definitely needs to exist before you run the script.
Good luck
Damn! now I don't want to sleep, PS + Python, Yay!
@Ben: Python and Photoshop is gonna be so much win