A co-worker of mine is writing a tool to automate tasks in Photoshop, and found a win32 error we can't explain. And possibly a bug.
The following script generates an error about how Select() can only take one-dimensional arrays: import win32com.client ps_app = win32com.client.Dispatch('Photoshop.Application') ps_app.Documents.Add(128, 128, 72) # select a 10x10 square in the upper left corner of the document sel_area = ((0, 0), (10, 0), (10, 10), (0, 10), (0, 0)) ps_app.ActiveDocument.Selection.Select(sel_area) The error: com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop', 'Illegal argument - argument 1\n- Only arrays with dimension 1 are supported', None, 0, -2147220262), None) File "c:\Python_Scripts\COM\Photoshop\selectionTest.py", line 7, in <module> ps_app.ActiveDocument.Selection.Select(sel_area) File "C:\Python25\Lib\site-packages\win32com\gen_py\E891EE9A-D0AE-4CB4-8871-F92C0109F18Ex0x9x0.py", line 2606, in Select , Type, Feather, AntiAlias) The problem is that that method is documented as taking two dimensional arrays. Here's an exerpt from the Photoshop CS3 VBScript Ref doc: docH = appRef.ActiveDocument.Width / 2 docV = appRef.ActiveDocument.Height / 2 selRegion = Array( Array( topLeftH * docH, topLeftV * docV), _ Array( topLeftH * docH + docH, topLeftV * docV), _ Array( topLeftH * docH + docH, topLeftV * docV + docV), _ Array( topLeftH * docH, topLeftV * docV + docV), _ Array( topLeftH * docH, topLeftV * docV)) appRef.ActiveDocument.Selection.Select(selRegion) It makes sense that it has to take a sequence of two-element sequences, right? Oddly enough, if you run the above code using the comtypes extensions instead of win32com, it works perfectly. The first two lines then become: import comtypes.client ps_app = comtypes.client.CreateObject('Photoshop.Application') Any ideas why this throws an exception with win32com.client/Dispatch? Is this a bug? Thanks in advance. - Adam
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32