Open cyberneticspk opened 1 year ago
@cyberneticspk
Please post your relevant code so that we can help you find out why this happens
@loonghao
Hi loonghao, Please help me, and thanks in advance.
I am developing Python module merging two images into one document in Photoshop environment.
Below is suurce code. I am trying to replace newly created Layer1 with image named "mcut_fg", and there already exists "mcut_bg" image on background Layer0 in document when opening new session. But, Exception occurs at "ps.app.executeAction(replace_contents, desc)" function at line 16 in ergeImageLayer(). And the photoshop application pop up following error message, "the command replace content is currently not available", the same greeting message issued by "@cyberneticspk"
I copied Traceback messages in RUN console and DEBUG console into hear.
Please help....! And thanks a lot...
from photoshop import Session
def mergeImageLayer(image_path) :
doc = ps.active_document
new_image_layer = doc.artLayers.add()
new_image_layer.kind = ps.LayerKind.NormalLayer
input_file = image_path
replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
desc = ps.ActionDescriptor
idnull = ps.app.charIDToTypeID("null")
desc.putPath(idnull, input_file)
ps.app.executeAction(replace_contents, desc) # Line 16 <-------- !!!!! exception occur here !!!!!!!!!!!!!!!!
with Session(file_path="D:\PycharmProjects\photoshop\exam\image\mcut_bg.jpg" , action="open") as ps :
mergeImageLayer("D:\PycharmProjects\photoshop\exam\image\mcut_fg.jpg")
Traceback (most recent call last):
File "D:\PycharmProjects\photoshop\exam\ImageMerge.py", line 23, in
Process finished with exit code 1
exception = {tuple: 3}(<class '_ctypes.COMError'>, COMError(-2147212704, None, (None, None, None, 0, None)), <traceback object at 0x000002433CA3E780>) a = {int} 287 argerr = {c_ulong} c_ulong(0) array = {tagVARIANT_Array_3: 3} <comtypes.automation.tagVARIANT_Array3 object at 0x000002433CA43250> dp = {tagDISPPARAMS} <comtypes.automation.tagDISPPARAMS object at 0x000002433CA43950> i = {int} 2 invkind = {int} 1 lcid = {int} 0 memid = {int} 1349280121 self = {POINTER(Dispatch)} <POINTER(IDispatch) ptr=0x2433b9093e8 at 2433ca42750> var = {tagVARIANT} VARIANT(vt=0x0, None)
When I ran the 'Emboss Action' example, the same error occurred in the first app.executeAction
function
Traceback (most recent call last):
File "C:\repos\photoshop_plugin\main.py", line 20, in <module>
app.executeAction(idPly, desc8, ps.DialogModes.DisplayNoDialogs)
File "C:\Users\changesong\.conda\envs\photoshop_plugin\lib\site-packages\photoshop\api\application.py", line 354, in executeAction
return self.app.executeAction(event_id, descriptor, display_dialogs)
File "C:\Users\changesong\.conda\envs\photoshop_plugin\lib\site-packages\comtypes\client\lazybind.py", line 182, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
File "C:\Users\changesong\.conda\envs\photoshop_plugin\lib\site-packages\comtypes\automation.py", line 745, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147212704, None, (None, None, None, 0, None))
I'll also write down the variables in the debug console like the above.
__exception__ = {tuple: 3} (<class '_ctypes.COMError'>, COMError(-2147212704, None, (None, None, None, 0, None)), <traceback object at 0x00000215564AFE00>)
a = {int} 1349286176
argerr = {c_ulong} c_ulong(0)
args = {tuple: 3} (1349286176, <comtypes.client.lazybind.Dispatch object at 0x00000215553CEE50>, <DialogModes.DisplayNoDialogs: 3>)
array = {tagVARIANT_Array_3: 3} <comtypes.automation.tagVARIANT_Array_3 object at 0x000002155638E540>
dp = {tagDISPPARAMS} <comtypes.automation.tagDISPPARAMS object at 0x0000021554E687C0>
i = {int} 2
invkind = {int} 1
lcid = {int} 0
memid = {int} 1349280121
self = {POINTER(IDispatch)} <POINTER(IDispatch) ptr=0x21552107468 at 21554cd3f40>
var = {tagVARIANT} VARIANT(vt=0x0, None)
In debug mode, the variables for main.py
are shown below.
app = {Application} Application <Photoshop.Application.170>
desc8 = {Dispatch} <comtypes.client.lazybind.Dispatch object at 0x00000215553CEE50>
idASet = {int} 1095984500
idActn = {int} 1097036910
idPly = {int} 1349286176
idnull = {int} 1853189228
index = {int} 0
ps = {Session} <photoshop.session.Session object at 0x00000215553BA8B0>
ref3 = {Dispatch} <comtypes.client.lazybind.Dispatch object at 0x00000215553BAC40>
x = {int} 0
I'm using Windows 10 Pro 21H2 and Photoshop 24.1.
I am using Adobe Photoshop CC2019. I am trying to replace an image in a layer. but i am always greeted with the error "the command replace content is currently not available"