photoshop-scripting-python
photoshop-scripting-python copied to clipboard
Cannot apply content aware filter to selected area.
Hello, I am trying to apply a content aware fill to a selected area in my currently opened Photoshop doc. However, when I try to run .putEnumerated
with "contentAware" as an option, Python throws the following error:
desc12.putEnumerated( idUsng, idFlCn, idcontentAware )
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py",
line 516, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'Illegal argument - argument 1\n-
Required value is missing', None, 0, -2147220262), None)
I am running this code with Python 3.7.6 on Windows Server 2019. I have successfully ran all the example code in this repo, but, again, the "contentAware" keyword seems to throw everything off. It is not clear what the "required value" is, per the error message, I have written the StringIDToTypeID and CharIDToTypeID the same as in the example code. Full code is below:
# Get the active document and make a new selection.
import sys
from comtypes.client import GetActiveObject, CreateObject
from win32com.client import Dispatch
xPoint = int(sys.argv[2])
yPoint = int(sys.argv[3])
xWidth = int(sys.argv[4])
yWidth = int(sys.argv[5])
xSw = xPoint + xWidth
ySh = yPoint + yWidth
dialogMode = 3
# Make sure PS is OPEN here...
app = GetActiveObject("Photoshop.Application")
docRef = app.open(sys.argv[1])
# Make selection on document according to args
activeObj = app.ActiveDocument
sel_area = ((xPoint, yPoint), (xSw, yPoint), (xSw, ySh), (xPoint, ySh))
docRef.Selection.Select(sel_area, 1, 5.5, False) # Get rid of last three args
idFl = app.CharIDToTypeID( "Fl " )
desc12 = Dispatch('Photoshop.ActionDescriptor')
idUsng = app.CharIDToTypeID( "Usng" )
idFlCn = app.CharIDToTypeID( "FlCn" )
idcontentAware = app.StringIDToTypeID("contentAware")
desc12.putEnumerated( idUsng, idFlCn, idcontentAware )