Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to use a script to copy the currently selected layer to all open documents, keeping the name and

Explorer ,
Jun 02, 2024 Jun 02, 2024

Copy the currently selected layer to all open documents, keeping the name and position intact How can I accomplish this using a photoshop script? I have searched for a long time and can't seem to find the right script. Hope you can help me out.

TOPICS
Actions and scripting
211
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jun 02, 2024 Jun 02, 2024

 I found one

if( app.documents.length > 0 ){
  duplicateToAll();
}
function duplicateToAll(){
  docs = app.documents;
  curDoc = app.activeDocument;
  groupLayerset();
  for(var i = 0; i < docs.length; i++){
    if(curDoc != docs[i]){
      var curLayer;
      try { curLayer = docs[i].activeLayer; } catch(e) {}
      curDoc.activeLayer.duplicate(docs[i],ElementPlacement.PLACEATBEGINNING);
      app.activeDocument = docs[i];
      app.activeDocument.activeLayer.name = 'Duplicate To All Group';
   
...
Translate
Adobe
Explorer ,
Jun 02, 2024 Jun 02, 2024

 I found one

if( app.documents.length > 0 ){
  duplicateToAll();
}
function duplicateToAll(){
  docs = app.documents;
  curDoc = app.activeDocument;
  groupLayerset();
  for(var i = 0; i < docs.length; i++){
    if(curDoc != docs[i]){
      var curLayer;
      try { curLayer = docs[i].activeLayer; } catch(e) {}
      curDoc.activeLayer.duplicate(docs[i],ElementPlacement.PLACEATBEGINNING);
      app.activeDocument = docs[i];
      app.activeDocument.activeLayer.name = 'Duplicate To All Group';
      if(curLayer){docs[i].activeLayer.move(curLayer, ElementPlacement.PLACEBEFORE);}
      ungroupLayerset();
    }
    app.activeDocument = curDoc;
  }
  ungroupLayerset();
  alert('"Duplicate to All" complete');
}
function ungroupLayerset(){
  var m_Dsc01 = new ActionDescriptor();
  var m_Ref01 = new ActionReference();
  m_Ref01.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );
  m_Dsc01.putReference( cTID( "null" ), m_Ref01 );

  executeAction( sTID( "ungroupLayersEvent" ), m_Dsc01, DialogModes.NO );
}
function cTID(s){return charIDToTypeID(s)}
function sTID(s){return stringIDToTypeID(s)}
function groupLayerset(){
  var desc = new ActionDescriptor();
  var ref = new ActionReference();
  ref.putClass( stringIDToTypeID('layerSection') );
  desc.putReference( charIDToTypeID('null'), ref );
  var ref = new ActionReference();
  ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
  desc.putReference( charIDToTypeID('From'), ref );

  executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2024 Jun 02, 2024
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines