Hi folks, here is a few findings about python script controlling Photoshop.
I’m using python 2.7 x64, Photoshop CS6 (x64), on win7 pro x64.
I’ve found different stuff looking into it for a few tools here, and though about sharing it so other people can get it and enhance all that. Let’s share thinking, new function etc, seems there is lot that can be done.
First, like ever posted, here is how to ‘connect’ to Photoshop:
If Photoshop isn’t started, it will start it.
from win32com.client import Dispatch
psApp = Dispatch("Photoshop.Application")
open some files into Photoshop, then try this:
# Some index infos:
PsDocumentMode = ["none", "Grayscale", "RGB", "CMYK", "Lab", "Bitmap", "IndexedColor", "MultiChannel", "Duotone"]
PsLayerType = ["none", "psArtLayer", "psLayerSet"]
PsBlendMode = ["none", "psPassThrough", "psNormalBlend", "psDissolve", "psDarken", "psMultiply",
"psColorBurn", "psLinearBurn", "psLighten", "psScreen", "psColorDodge", "psLinearDodge", "psOverlay",
"psSoftLight", "psHardLight", "psVividLight", "psLinearLight", "psPinLight", "psDifference", "psExclusion",
"psHue", "psSaturationBlend", "psColorBlend", "psLuminosity", "psHardMix", "psLighterColor", "psDarkerColor",
"psSubtract", "psDivide"]
PsElementPlacement = ["none", "psPlaceInside", "psPlaceAtBeginning", "psPlaceAtEnd", "psPlaceBefore", "psPlaceAfter"]
# open documents:
openDocs = psApp.Application.Documents
print "Number of open docs:", openDocs.Count
print [openDocs[i].name.encode('cp1252') for i in range(0, openDocs.Count)]
# active document:
doc = psApp.Application.ActiveDocument
print "
Active documents:", doc.name
print " Doc size:", int(doc.width), int(doc.height)
print " Doc path:", doc.path
print " Doc mode:", PsDocumentMode[doc.mode]
print " Doc BitsPerChannel:", doc.BitsPerChannel
print "ActiveChannels:", [channel.name for channel in doc.ActiveChannels]
try:
profil = doc.ColorProfileName
except:
profil = "Untagged"
print " Doc ColorProfileName:", profil
print " Doc Resolution: %sdpi" %doc.Resolution
# some properties:
print "
Some properties:"
myLayer = doc.ActiveLayer
print "Blend mode:", PsBlendMode[myLayer.BlendMode]
print "Bounds:", myLayer.Bounds # detect empty layers !!!
print "Lock:", myLayer.AllLocked
print "FillOpacity:", myLayer.FillOpacity
print "Opacity:", myLayer.Opacity
print "Visible:", myLayer.Visible
print "Type:", myLayer.typename
A few more stuff (some code delete and alter layers, so all is commented) :
#select entire aera:
#doc.Selection.SelectAll()
#copy it to clipboard:
#doc.Selection.Copy()
#remove selection:
#doc.Selection.Deselect()
#newLayer = doc.ActiveLayer.Duplicate()
#newLayer.Delete()
#New layer or Group:
#doc.artLayers.add
#doc.layerSets.add
# Move layers:
#doc.Layers("Layer 4").Move(doc.Layers("Layer 3"), 4) #3:top, #4:bottom
# flatten doc:
#doc.MergeVisibleLayers
# Close PSD without saving:
#doc.Close(2)
# Save:
#doc.Save()
Finally some resources :
http://www.adobe.com/devnet/photoshop/scripting.html
Get Photoshop CS6 VBScript Reference.pdf, there is all vbscript functions into.
Next part will be more fun …