Skip to main content
Inspiring
November 9, 2023
Answered

Scripting - Paste content inside existing layer.

  • November 9, 2023
  • 1 reply
  • 502 views

This is a tough one to solve...

 

Imagine this situation... I have one normal layer (ArtLayer) that has a mask (UserMask) and two adjustmentlayers linked to this layer.

The goal is to replace the content of the layer, this content is already copied, so it just needs to paste inside this layer.

 

The problem is that if the layer is linked to any adjustmentlayers OR the mask is chained to the RGB layer (as by default) OR if there is already content inside the RGB it only creates a new layer instead of pasting it in the existing layer. So if there are no linked layers, no mask, and clear the content before pasting, it does work correctly.

 

I tried serveral methodes to get this to work, but so far no solution. I tried unlinking the layers, but I cannot unchain the mask using scripts, maybe someone here can? I also tried to add a layer reference to the past action manager function, but it seems to ignore that, but I could have implemented it incorrectly.

 

I know I could use smartObjects instead, I know how I can make that work, but it has a performance hit when updating these layers, so I would first try all my options before resorting to that solution.

 

I also tried the "paste inside" paste, but with the same results. Also as suggested past, and merge down, but I'm not sure if thats a good solution, I think it may cause unexptected results in some situations, but I will test that for sure.

 

I hope some wizard can come up with some action manager code that effectively can paste the content in the target layer without changing linked layers, masks, blending modes, transparancies, and so forth.

This topic has been closed for replies.
Correct answer Stephen Marsh

Untested as I'm not in front of Photoshop...

 

EDIT: I have just tested!

 

But select all before pasting? << Didn't work

 

Instead of copy/paste, why not apply image from source to destination doc (presuming same pixel dimensions etc)? Or paste in a new layer and apply image from layer to layer then delete the temp layer. << Both methods worked!

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
November 9, 2023

Untested as I'm not in front of Photoshop...

 

EDIT: I have just tested!

 

But select all before pasting? << Didn't work

 

Instead of copy/paste, why not apply image from source to destination doc (presuming same pixel dimensions etc)? Or paste in a new layer and apply image from layer to layer then delete the temp layer. << Both methods worked!

 

Marvin01Author
Inspiring
November 9, 2023

Thanks for the feedback! I didn't know about the "apply image" function, never used it.

Your right, it does work when I try it manually. I guess the apply image function can also be scripted? Given a source doc and target doc + target layer. Or just source layer and target layer?

I will dive into that methode ones I have the time.

For now, I just managed to finished a working function that CAN pastes inside a layer, but it's complicated, and required allot of action manager code to control chaining of masks and detect the chain and linked layers.

But it works now with linked layers, with or without a mask with or without  a mask chain.

 

When a linked and mask chained layer is involved it will: unchain mask, selectRGB, select all, fillColor, paste, and than merging below. The fill color is done to make sure the merge is complete.

When the layer is mask chained but not linked it will use delete instead of a fill and the merge function at the end is not needed because it will paste in the target layer directly. The function reapplies the chain or visibility depending on the initial layer properties.

Stephen Marsh
Community Expert
Community Expert
November 9, 2023

Apply Image and Calculations are old school.

 

Yes, action manager code recorded via the ScriptingListener plugin. You can swap out the recorded static names and replace them with DOM code for the document/documents or layer/layers collection etc.

 

 It depends on the source (document or layer) and destination (layer).

 

Apply Image bypasses the clipboard so it's fast.

 

You can find various code examples by searching the forum for the keyword applyImage()