I posted a blog on how to automate Photoshop using Python, with some example scripts. Hope someone finds it useful.
http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html
I posted a blog on how to automate Photoshop using Python, with some example scripts. Hope someone finds it useful.
http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html
Thanks Adam. I was thinking about this just last week! Itâs like youâve got some kind of mind reading ability.
import telepathy
Iâm a fan of javascript so I never thought about doing this but it makes sense why one would. Thank you for sharing this Adam!
Where would we be w/o standardized interfacesâŚ
âŚ
Ahh, thatâs cool! Iâve just started learning Python recently for Maya usage, but itâs very cool to see examples of it controlling Photoshop here, and Chris Evans demonstrated nicely how to control Motion Builder with it too, so it seems like the best language for me to learn right now
Finally had a chance to test it this evening. Man, it works fast. I can see this being exceptionally useful, especially if I can get it working for After Effects too. Thanks again Adam.
NP. You can do this with any program that registers a COM interface. I donât have After Effects, but I imagine it provides that.
You can use any language that supports COM/OLE objects to do this. Thatâs one of the main features of COM, that itâs language-independent.
[QUOTE=Adam Pletcher;853]NP. You can do this with any program that registers a COM interface. I donât have After Effects, but I imagine it provides that.
You can use any language that supports COM/OLE objects to do this. Thatâs one of the main features of COM, that itâs language-independent.[/QUOTE]
It does (After Effects has the same interface and scripting options as PS), but I canât get the fundamental part working⌠ie. the client.Dispatch name!
Normally com dispatches are done via âX.Applicationâ where X = the app progID in question (such as âExcel.Applicationâ or âMAX.Application.2009â), but i canât get AE (ie. âAfterFX.Applicationâ) to register. I probably have the wrong name, but my ignorance is showing about identifying COM Objects.:D:
EDIT: Turns out iâm an idiot⌠theyâre right there in PythonWin tools⌠And no, AE doesnât have one! I may have to set up an automation entry.
Yet another killer example, Adam. Thanks a bunch for this; it was very enjoyable to pick apart:):.
[QUOTE=Adam Pletcher;846]I posted a blog on how to automate Photoshop using Python, with some example scripts. Hope someone finds it useful.
http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html[/QUOTE]
Sweet! Thank you mucho for showing this. Been needing to automate Photoshop forever now. Will try at work tomorrow.
Excellent timing, Iâm just about to start looking into this so itâll be a great help. Thanks!
Hello.
Iâm implementing photoshop script via python by reference to Adamâs site.
(Thank you for very useful information!)
But I encountered a problem about dealing with HDRI format (such as Tiff 32bit).
I attempted to apply Blur filter to Tiff32bit image by using applyBlur() function of âArtLayerâ.
But I canât do it. Photoshop output an error. (you canât use âapplyBlur()â currently.)
So I guess it seems that Photoshop script doesnât support for filter function of HDRI.
Iâm using PhotoshopCS2. So, when I apply the Blur Filter to HDRI manually, I can do that.
Have you ever implemnted photoshop script for dealing with HDRI?
This is the simple source which I mentioned above.
Could you give me helpful advice, please?
import win32com.client
psApp = win32com.client.Dispatch('Photoshop.Application')
doc = psApp.Open(r"C:/Temp/test.tif"))
for layer in doc.Layers:
layer.applyBlur()
doc.Save()
Thanks
If you change âlayer.applyBlur()â to âlayer.ApplyBlur()â it works, at least for me. Like regular Python functions, com methods are case-sensitive.
[edit] Ah, right, like you said ApplyBlur doesnât work on HDR images. Iâd venture a guess that the Filters have to be specifically written to support HDR/32 bit color. If you go to the Filter/Blur menu, âBlurâ is disabled but a few others are not. For instance, this one works:
layer.ApplyGaussianBlur(13)
I should add, Iâm using CS3. Hope that helps.
This is great, Python is next on my list to learn. By the way is it possible to use photoshop functions without opening Photoshop? If I for example make an application which converts psd files to png and applies a Photoshop filter to them?
No, the act of applying a filter still requires Photoshop to be running. Even if Python is pulling the strings, the Photoshop app is open, doing the legwork.
I need to ask: Why the hell isnât there a 2d app with a proper scripting environment?
Imagine PS with the ability to customize like maya or xsi. the things we could do!
[QUOTE=Adam Pletcher;4766]If you change âlayer.applyBlur()â to âlayer.ApplyBlur()â it works, at least for me. Like regular Python functions, com methods are case-sensitive.[/QUOTE]
> Adam
Thank you for your information. Like you said, I made a mistake the spell of com methods. After that, I could execute the script. Thank you!
But I have an another issue about Photoshop scripts.
Iâm trying to set the Gamma value â2.2â to HDR Image via Photoshop script.(Menu:Image -> Adjustments -> Exposure -> Gamma )
I found the appropriate command is âadjustLevelsâ method of âArtLayerâ from âJavaScript Referece Guideâ.
As well as the previous one, I wrote the following source code.
import win32com.client
psApp = win32com.client.Dispatch('Photoshop.Application')
doc = psApp.Open(r"C:/Temp/test.tif"))
for layer in doc.Layers:
[B]layer.adjustLevels(0,255,2.2,0,255)[/B]
doc.Save()
However, Photoshop also output an error.
[B] File âC:\Python26\lib\site-packages\win32com\client\dynamic.pyâ, line 495, in getattr
raise pythoncom.com_error, details pywintypes.com_error:
(-2147352567, âException occurred.â, (0, uâAdobe Photoshopâ, uâIllegal argument - argument 1
It seems that I made a mistake for the usage of the function. But I canât figure out this error.
So I would like to know the useful informations for association âan operation on Photoshopâ with âPhotoshop script commandâ!
Could you tell me other useful informations for that? (except JavaScriptReferenceGuide.pdf)
Thanks,
dragonboy, a few things came off a bit different from Adamâs blog. You defined doc as the psAppâs .Open function instead of the it looking at the Application.ActiveDocument. Also, Iâve seen no difference in choosing ArtLayers vs. Layers, but I switched it to that anyways⌠some of the syntax in that PDF describing them and their case sensitivity confuses me anyways :?:. Hope this helps!
You had an extra â)â in the psApp.Open function code you pasted for some reason as well but I can see you werenât getting that syntax error.
import win32com.client
psApp = win32com.client.Dispatch('Photoshop.Application')
psApp.Open(r"C:\Temp est.tif")
doc = psApp.Application.ActiveDocument
layer = doc.ArtLayers[0]
layer.AdjustLevels(0, 255, 2.2, 0, 255)
doc.Save()
Thanks Adam! So hot.
You mention that photoshop supports several different COM interfaces, but i havenât had much luck finding documentation on them. Do you have any suggestions on where I should be digging?
I gave up the python approach this timeâŚ
I remembered that Photoshop provides a convenient plugin âScriptingListenerâ.
So I decided to use this plugin to execute automatic operation on Photoshop.
But, as you know, ScriptingListener output JavaScriptâs log.
So I couldnât use Adamâs useful approach. Thatâs too bad
[edit]
> Kovac
Thank you for your information. I changed the code as you adviced. But Photoshop output the same errorâŚ
So I decided to change the approach by using âScriptingListenerâ.
Thanks anyway.