Layer via copy

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

j_man

Layer via copy

Post by j_man »

Hello,

I want o perform a "Layer via copy" on a layer when I have something selection. The script below doesn't work as I don't know what I'm doing!

My aim is to turn each channel of one layer into a new layer copied from a layer called "RGB". I hope this makes sense.

Code: Select allfunction main()
{
   if (documents.length > 0)
   {
   // Create a reference to the active document.
      var docRef = activeDocument
   // Make some variables
      var layerNum =      docRef.artLayers.length      // the number of layers
      // Search through each layer to find the RGB layer
      for(i=layerNum-1;i>=0;i--)
      {
   // search the layer name for the string to identify what layer it is
         if(docRef.artLayers.name.indexOf("RGB")==0)
            var RGBlayer = docRef.artLayers
      }
      docRef.selection.load(docRef.channels["Red"], SelectionType.REPLACE, false);
      var newlayer = docRef.artLayers.add() //my target layer for the copied image
      docRef.activeLayer = RGBlayer //make the RGB layer active
      docRef.selection.copy()
      docRef.newlayer.paste()
   }
}
main();

Any help appreciated!

Josh.
j_man

Layer via copy

Post by j_man »

OK I'm missing the semicolons. Still any help appreciated!

Code: Select allfunction main()
{
   if (documents.length > 0)
   {
   // Create a reference to the active document.
      var docRef = activeDocument
   // Make some variables
      var layerNum =      docRef.artLayers.length      // the number of layers
      // Search through each layer to find the RGB layer
      for(i=layerNum-1;i>=0;i--)
      {
   // search the layer name for the string to identify what layer it is
         if(docRef.artLayers.name.indexOf("RGB")==0)
            var RGBlayer = docRef.artLayers
      }
      docRef.selection.load(docRef.channels["Red"], SelectionType.REPLACE, false);
      var newlayer = docRef.artLayers.add() //my target layer for the copied image
      docRef.activeLayer = RGBlayer //make the RGB layer active
      docRef.selection.copy();
      docRef.paste();
   }
}
main();
j_man

Layer via copy

Post by j_man »

Wow I know I ask the tough questions but I am surprised that no-one knows how to do a layer via copy!

J.
pfaffenbichler

Layer via copy

Post by pfaffenbichler »

Are you joking or are you under some misapprehensions regarding this Forum?
And why do you post on the »General Discussion« Forum when you want assistance instead of on the »Help Me« Forum?
Edit: Furthermore I consider it less than ideal to reply to one’s own original post, especially more than once, as for me at least a post with 0 replies seems more noteworthy when I try to provide assistance than one that has already been addressed (repeatedly).

Anyway … 
Code: Select all// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
j_man

Layer via copy

Post by j_man »

Hello pfaffenbichler,

Thank you for your response, it does work but I am unsure of how I can put the new layer into an variable. Using paste() I can simply assign it so, but the paste command does not always paste in place.

Code: Select allnewlayer = docRef.paste();


pfaffenbichler wrote:Are you joking or are you under some misapprehensions regarding this Forum?

Both maybe.

pfaffenbichler wrote:And why do you post on the »General Discussion« Forum when you want assistance instead of on the »Help Me« Forum?

Because I am new am am not yet completely confident with the structure of this form.

pfaffenbichler wrote:Edit: Furthermore I consider it less than ideal to reply to one’s own original post, especially more than once, as for me at least a post with 0 replies seems more noteworthy when I try to provide assistance than one that has already been addressed (repeatedly).

Interesting idea, I always found it useful when people post the progress they make rather than a "Oh solved it thanks" without ever telling anyone what they figured out. Plus more posts make more interesting reading.
pfaffenbichler

Layer via copy

Post by pfaffenbichler »

If someone has solved their original issue in a thread it is certainly considerate of them to explain that for the benefit of others who may have similar problems.

After »Layer Via Copy« you could define the newly created and thus active Layer as a new variable
Code: Select allvar id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
var theCopiedLayer = app.activeDocument.activeLayer;
j_man

Layer via copy

Post by j_man »

Hi,

I see that makes perfect sense. Thanks again for your help.


Regards,

Josh.