-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot replace an image layer #177
Comments
Sorry but I can't help you directly. Though this happened to me too (including the code working only once), and I worked around it by simply importing the new image and getting rid of the old one in another way. |
Thanks, I will give it a try. |
Have you tried to look at #174? What's missing in your code is setting the active layer: |
@Edimo05
|
@loonghao I tried this code (https://loonghao.github.io/photoshop-python-api/examples/#replace-images) but I cannot import examples._psd_files. I already installed photoshop_python_api. |
@blunderedbishop I tried change my code to this: and it shows next error: maybe I placed that code u mentioned wrong? |
@Edimo05
with Session() as ps:
ps.active_document.activeLayer = doc.artLayers.getByName("08")
replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
desc = ps.ActionDescriptor
idnull = ps.app.charIDToTypeID("null")
desc.putPath(idnull, r"G:\BLEBLE\BLABLABLA\BLABLABLA\BLABLABL\BLABLA\2022\August\Images\09.jpeg")
ps.app.executeAction(replace_contents, desc) |
@loonghao now is showing this error: |
|
@loonghao nothing man, same error: Traceback (most recent call last): |
@Edimo05 Please convert the 08 layer as a smart-object first and then execute the following code from photoshop import Session
with Session() as ps:
doc = ps.active_document
doc.activeLayer = doc.artLayers.getByName("08")
replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
desc = ps.ActionDescriptor
idnull = ps.app.charIDToTypeID("null")
desc.putPath(idnull, r"G:\BLEBLE\BLABLABLA\BLABLABLA\BLABLABL\BLABLA\2022\August\Images\09.jpeg")
ps.app.executeAction(replace_contents, desc) |
@loonghao finally works. That layer was already an smart object, I think I missed ps.active_document. |
@Edimo05 good to hear, closing issue. |
Describe the bug
I am trying to replace an image layer in a photoshop file. For that purpose I am using this next code:
To Reproduce
This is my python code:
with Session() as ps:
replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
desc = ps.ActionDescriptor
idnull = ps.app.charIDToTypeID("null")
desc.putPath(idnull, "G:\BLEBLE\BLABLABLA\BLABLABLA\BLABLABL\BLABLA\2022\August\Images\09.jpeg")
ps.app.executeAction(replace_contents, desc)
Expected behavior
It suppose to replace already existing image layer but instead of thar it show an error message and log.
Screenshots
![image](https://user-images.githubusercontent.com/94873872/184283241-c3b7a0b7-ef67-46a3-9877-6b5102a92d30.png)
Photoshop error message:
Terminal message:
Traceback (most recent call last):
File "g:\Blebleble\blablabla\blablabla\blablabla\Publicaciones\AUTOMATION\automate.py", line 43, in
ps.app.executeAction(replace_contents, desc)
File "C:\Users\bliblibli\AppData\Local\Programs\Python\Python310\lib\site-packages\photoshop\api\application.py", line 355, in executeAction
return self.app.executeAction(event_id, descriptor, display_dialogs)
File "C:\Users\bliblibli\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\client\lazybind.py", line 182, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
File "C:\Users\bliblibli\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\automation.py", line 745, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147213497, None, (None, None, None, 0, None))
Desktop (please complete the following information):
Additional context
This code actually worked once but suddenly it stopped working.
The text was updated successfully, but these errors were encountered: