我正试图用Photoshop API中包含的MakeContactSheet
函数制作一个Photoshop联系人表。可以使用“win32com.client”访问它
我的第一行:
psApp = Dispatch("Photoshop.Application")
创建一个win32com.gen_py.E891EE9A-D0AE-4CB4-8871-F92C0109F18Ex0x1x0._Application._Application
对象
该对象的类似乎具有documentation中列出的所有可用函数
然后,我继续使用os.walk创建字符串列表
CSInputFiles = [path.join(r, f) for r, sd, fs in walk('C:\\Users\\chris\\Desktop\\1A') for f in fs]
然后是一组混合选项:
CSoptions = [True, psApp, False, False, 6, True, None, 0, 7, 4, 3, 300, 3, None, True]
最后,我传递这些论点:
psApp.MakeContactSheet(CSInpuFiles, CSoptions)
考虑到_Application
中的函数定义,这似乎是正确的:
def MakeContactSheet(self, InputFiles=defaultNamedNotOptArg, Options=defaultNamedOptArg):
'create a contact sheet from multiple files'
# Result is a Unicode object
return self._oleobj_.InvokeTypes(1129599816, LCID, 1, (8, 0), ((12, 1), (12, 17)),InputFiles
, Options)
唉,我得到了以下错误:
Traceback (most recent call last):
File "C:\Users\chris\Desktop\test.py", line 17, in <module>
psApp.MakeContactSheet(CSInputFiles, CSoptions)
File "C:\Users\chris\AppData\Local\Temp\gen_py\3.9\E891EE9A-D0AE-4CB4-8871-F92C0109F18Ex0x1x0\_Application.py", line 97, in MakeContactSheet
return self._oleobj_.InvokeTypes(1129599816, LCID, 1, (8, 0), ((12, 1), (12, 17)),InputFiles
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'Illegal argument - argument 2\n- Object expected', None, 0, -2147220261), None)
我最初的直觉是使用pathlib将csInputFiles数组中的所有字符串转换为path对象
from pathlib import Path
CSInputFiles = [Path(path.join(r, f)) for r, sd, fs in walk('C:\\Users\\chris\\Desktop\\1A') for f in fs]
当我将数组传递给函数时,产生了这段模糊的垃圾:
psApp.MakeContactSheet(CSInputFiles, CSoptions)
#RUN!
File "C:\Users\chris\Desktop\test.py", line 17, in <module>
psApp.MakeContactSheet(CSInputFiles, CSoptions)
File "C:\Users\chris\AppData\Local\Temp\gen_py\3.9\E891EE9A-D0AE-4CB4-8871-F92C0109F18Ex0x1x0\_Application.py", line 97, in MakeContactSheet
return self._oleobj_.InvokeTypes(1129599816, LCID, 1, (8, 0), ((12, 1), (12, 17)),InputFiles
TypeError: must be real number, not WindowsPath
这根本没有道理!它怎么会期望一个真实的数字呢?这是一个输入文件数组
问题中指定的错误是因为我将options参数设置为列表而不是对象。有关对象结构的信息,可以查看here
然而,在对GitHub进行了一些询问之后,我发现
MakeContactSheet
是一个不推荐使用的函数,如this文档第19页所述这导致我使用枕头库开发了一种替换品
解决方法是简单地创建一个空的
png
,然后将所有要放在联系人表上的图像粘贴到该png
上为了解决这里的问题,我将粘贴这个程序的简化版本
如上所述,这是一个非常粗糙的示例,它基于我编写的最终程序的更复杂版本。但我已经超越了相关性的界限
相关问题 更多 >
编程相关推荐