-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Description
I'm trying to add guides to the active document, but the 2 methods I'm aware of don't work.
- Eval as Javascript
When using the following string
app.activeDocument.guides.add(constant.Direction.HORIZONTAL,30)
It produces a COM error.
Traceback (most recent call last):
File "D:\Alchemy\src\PSUtils\Guides.py", line 65, in <module>
guides.add(1, 64)
~~~~~~~~~~^^^^^^^
File "D:\Alchemy\src\PSUtils\Guides.py", line 48, in add
result = self._app.eval_javascript(js_code)
File "D:\Alchemy\.venv\Lib\site-packages\photoshop\api\_core.py", line 218, in eval_javascript
return executor.doJavaScript(javascript, Arguments, ExecutionMode)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Alchemy\.venv\Lib\site-packages\comtypes\client\lazybind.py", line 160, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Alchemy\.venv\Lib\site-packages\comtypes\automation.py", line 852, in _invoke
self.__com_Invoke( # type: ignore
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
memid, riid_null, lcid, invkind, dp, var, None, argerr
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
_ctypes.COMError: (-2147212704, None, (None, None, None, 0, None))
This occurs with any positional value, and I've tried different orientation syntax to no success.
..ides.add(constant.Direction.HORIZONTAL,30)
..ides.add(constant.direction.HORIZONTAL,30)
..ides.add(direction.HORIZONTAL, 30)
..ides.add(0, 30)
- ActionDescriptor
I have also tried to use the action descriptor method, but this leads to a "Make not currently available" error which i believe is due to Photoshop wanting to use the previous JavaScript method in recent versions. It has been a while since I've written any action descriptor code, so perhaps i have written is wrong(?) I wrote this referencing a previous script I made which made use of batch play.
from photoshop import Session
with Session() as ps:
doc = ps.active_document
desc = ps.ActionDescriptor()
ref = ps.ActionReference()
ref.putClass(ps.app.stringIDToTypeID("guide"))
desc.putReference(ps.app.charIDToTypeID("null"), ref)
guideDesc = ps.ActionDescriptor()
guideDesc.putUnitDouble(ps.app.stringIDToTypeID("position"), ps.app.stringIDToTypeID("pixelsUnit"), 30)
guideDesc.putEnumerated(ps.app.stringIDToTypeID("orientation"), ps.app.stringIDToTypeID("orientation"), ps.app.stringIDToTypeID("horizontal"))
guideDesc.putEnumerated(ps.app.stringIDToTypeID("kind"), ps.app.stringIDToTypeID("kind"), ps.app.stringIDToTypeID("document"))
desc.putObject(ps.app.stringIDToTypeID("using"), ps.app.stringIDToTypeID("guide"), guideDesc)
ps.app.executeAction(ps.app.stringIDToTypeID("make"), desc)
Do we currently have a way to add guides to documents?
Thanks for your time
Metadata
Metadata
Assignees
Labels
No labels