Search code examples
pythonpython-2.7photoshopwin32com

Photoshop scripting with Python COM. Duplicate and flatten problems


I'm trying to merge some PS files, basically with two methods:

1) Flatten, SelectAll, Copy, change ActiveDocument and Paste. This one return a TypeError in the first step.

Traceback (most recent call last):
  File "C:\..\Merge.py", line 5, in <module>
    doc.flatten()
TypeError: 'NoneType' object is not callable
[Finished in 0.7s]

Inside Photoshop I can observe the document was flattened, but return this. stoping the script.

2) Duplicate LayerSet pointing to the targeted Document.

Traceback (most recent call last):
  File "C:\..\Merge.py", line 27, in <module>
    appRef.activeDocument.LayerSets[0].duplicate(appRef.documents[0]);  
  File "C:\python27-64\lib\site-packages\win32com\client\dynamic.py", line 197, in __call__
    return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
[Finished in 4.7s]

Same Here! The LayerSet was duplicated

  • Photoshop CC 2014 64bits
  • Python 2.7 64bits
  • Win32com for python 2.7 64bits

Solution

  • Apparently, there are troubles with win32com.

    comtypes works pretty well! re-installing python 2.7 64bits. Check "Install for me only" instead "Install for all users" then install comtypes.