Highlighted

Rename layers toUpperCase()

Community Beginner ,
Nov 10, 2020

Copy link to clipboard

Copied

Hello,

 

I've found this script here made by @Geppetto Luis :

https://community.adobe.com/t5/photoshop/change-layer-names-so-lowercase/td-p/9564258?page=1

 

But when i try to execute it in photoshop 2020, i've got an error :

error 1200 : internal error

-> docRef.activeLayer = docRef.layers

 

What i want to acheive is to do a sanity check on layer, 

rename layer.toUpperCase()

rename layer.replace(" ", "");

rename layer.replace(/^0+/g, "");

...

 

regards,

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

Here are the edits you requested (I believe) to the original script as "rescued" by Manan, however, it should be noted that even a locked Background "layer" will be promoted to a layer and made uppercase... Which may not be what you want?

 

var layerLength = app.activeDocument.layers.length;
var docRef = app.activeDocument;
for (i = 0; i < layerLength; i++) {
    docRef.activeLayer = docRef.layers[i];
    var myName = app.activeDocument.activeLayer.name;
    var refinedName = myName.toUpperCase().replace(/ /g, '').replace(/^0+/g, '');
    docRef.activeLayer.name = refinedName;
}

 

 

TOPICS
Actions and scripting, Windows

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Rename layers toUpperCase()

Community Beginner ,
Nov 10, 2020

Copy link to clipboard

Copied

Hello,

 

I've found this script here made by @Geppetto Luis :

https://community.adobe.com/t5/photoshop/change-layer-names-so-lowercase/td-p/9564258?page=1

 

But when i try to execute it in photoshop 2020, i've got an error :

error 1200 : internal error

-> docRef.activeLayer = docRef.layers

 

What i want to acheive is to do a sanity check on layer, 

rename layer.toUpperCase()

rename layer.replace(" ", "");

rename layer.replace(/^0+/g, "");

...

 

regards,

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

Here are the edits you requested (I believe) to the original script as "rescued" by Manan, however, it should be noted that even a locked Background "layer" will be promoted to a layer and made uppercase... Which may not be what you want?

 

var layerLength = app.activeDocument.layers.length;
var docRef = app.activeDocument;
for (i = 0; i < layerLength; i++) {
    docRef.activeLayer = docRef.layers[i];
    var myName = app.activeDocument.activeLayer.name;
    var refinedName = myName.toUpperCase().replace(/ /g, '').replace(/^0+/g, '');
    docRef.activeLayer.name = refinedName;
}

 

 

TOPICS
Actions and scripting, Windows

Views

71

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Try the following, the code you mentioned seems to have a type. The issue is not with what the script author wrote, when the forum migrated from the old platform to the new platform these issues crept in several code snippets throughout the forum

var layerLength = app.activeDocument.layers.length;
var docRef  = app.activeDocument;
for(i = 0; i < layerLength; i++){
   docRef.activeLayer = docRef.layers[i]
   var myName = app.activeDocument.activeLayer.name;
   var newName = myName.toLowerCase();
   docRef.activeLayer.name = newName;
 }

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2020 1
Community Beginner ,
Nov 11, 2020

Copy link to clipboard

Copied

Thank you @Manan Joshi !

 

I've just tick the correct answer to Stephen with the regex Part 😉

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Here are the edits you requested (I believe) to the original script as "rescued" by Manan, however, it should be noted that even a locked Background "layer" will be promoted to a layer and made uppercase... Which may not be what you want?

 

var layerLength = app.activeDocument.layers.length;
var docRef = app.activeDocument;
for (i = 0; i < layerLength; i++) {
    docRef.activeLayer = docRef.layers[i];
    var myName = app.activeDocument.activeLayer.name;
    var refinedName = myName.toUpperCase().replace(/ /g, '').replace(/^0+/g, '');
    docRef.activeLayer.name = refinedName;
}

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2020 1
Community Beginner ,
Nov 11, 2020

Copy link to clipboard

Copied

Thank you, 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0
Adobe Community Professional ,
Nov 11, 2020

Copy link to clipboard

Copied

Your welcome! I'm glad you don't care about the Background image "layer" being messed with, I couldn't figure out how to stop that happening in a global layer rename.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0
Community Beginner ,
Nov 11, 2020

Copy link to clipboard

Copied

Wich background Layer messed ? no...all working good.

I've forced to rename in lowerCase the Background image "layer" and all good.

Maybe because i merge all group before ?

 

My script do a sanity check of psd file :

- remove all hidden layers
- merge all groups
- clean layer name (thats your part)
- group layers (thats part of Manan Joshi  help

- convert to 16 bit depth file
- save file

 

here it is (if it help):

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global $, Folder*/

function saveFile(){
  var documents = app.activeDocument;
  var docName = app.activeDocument.name;
  var docPath = app.activeDocument.path.fsName;
  psdSaveOptions = new PhotoshopSaveOptions();
  psdSaveOptions.embedColorProfile = true;
  psdSaveOptions.alphaChannels = true;
  psdSaveOptions.layers = true;
  psdSaveOptions.annotations = true;
  psdSaveOptions.spotColors = true;

  var dptFind = 'BGLO'
  var match = docName.match(new RegExp(dptFind, "g"));
  if (match){
    var switchBaseName = docName.replace('BGLO', 'BGCO');
    var getEp = docName.split('_')[1];
    var colorPsdSaveServer = 'C:\\path\\' + getEp + '\\to\\' + switchBaseName;
    var colorPsdSaveLocal = File(docPath + '\\' + switchBaseName);
    documents.saveAs(colorPsdSaveLocal, psdSaveOptions, false, Extension.LOWERCASE);
  }
  else{
    var switchBaseName = docName.split('.')[0] + '_CO.psd';
    var getEp = docName.split('_')[0];
    getEp = getEp.split('R')[1];
    var colorPsdSaveServer = 'C:\\path\\' + getEp + '\\to\\other\\' + switchBaseName;
    var colorPsdSaveLocal = File(docPath + '\\' + switchBaseName);
    documents.saveAs(colorPsdSaveLocal, psdSaveOptions, false, Extension.LOWERCASE);
  }
}

function removeHiddenLayers(){
  for (i=app.activeDocument.layers.length; i>0; i--)
    {
      if (!app.activeDocument.layers[i-1].visible)
        {
          app.activeDocument.layers[i-1].remove();
        }
    }
}

function mergeAllGroups(){
  shotlayerssets = app.activeDocument.layerSets;
  for (i=shotlayerssets.length; i>0; i-- )
    {
      shotlayerssets[i-1].merge();
    }
}

function cleanLayerName(){
  var layerLength = app.activeDocument.layers.length;
  var docRef = app.activeDocument;
  for (i = 0; i < layerLength; i++) {
      docRef.activeLayer = docRef.layers[i];
      var myName = app.activeDocument.activeLayer.name;
      var refinedName = myName.toUpperCase().replace(/ /g, '');
      docRef.activeLayer.name = refinedName;
  }
}

function groupLayers(){
  var len = app.activeDocument.layers.length
  for (var i = len - 1; i >= 0; i--)
    {
		var layerName = app.activeDocument.layers[len - 1];
		if(layerName.isBackgroundLayer)
			continue;
		var groupName = app.activeDocument.layerSets.add();
		groupName.name = layerName.name;
		layerName.move(groupName, ElementPlacement.INSIDE);
    }
}

function convertBitDepth(){
   var id1 = charIDToTypeID( "CnvM" );
   var desc1 = new ActionDescriptor();
   var id2 = charIDToTypeID( "Dpth" );
   desc1.putInteger( id2, 16 );
   executeAction( id1, desc1, DialogModes.NO );
}

function mainRunner(){
  removeHiddenLayers()
  mergeAllGroups()
  cleanLayerName()
  groupLayers()
  convertBitDepth()
  saveFile()
}

mainRunner()

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2020 0