Skip to main content
Participating Frequently
September 14, 2011
Answered

Script to change Layer Name to Fill Pattern Name PLEASE HELP

  • September 14, 2011
  • 1 reply
  • 2579 views

I have an emergency here guys! I have over 2000 pattern files saved to a library. These patterns are all labeled with the same names that I want my layers to have. I will be making a New Layer for each pattern for a total of 2000 Layers. 2000 layers is way more layers then I want to name by hand, so if I can run a script to give the layers the same name as the pattern that they are filled with it would help tremendously.

Please help!

Thanks

This topic has been closed for replies.
Correct answer Paul Riggott

Ok guys I do have the pattern saved to a .pat file. These patterns are images of carpet and they are labled by style-color. They are all in the same library because they are all for the same project. I can get the name and Id for each one of these, but how do I get photoshop to put the pattern name as the layer name. With out having to type up a script for each pattern. I will only be using each pattern once.

Let me explain alittle better.

Here is the proccess I am going through now. I am makeing a monster file with a Fill Pattern layer for every carpet. I have linked the pattern to the layer so when I change the canvas size the patterns will auto generate to the canvas size.

Right now these are the steps for each layer.

1.) Create new Fill Pattern layer

2.) Select the pattern that I want to use.

3.) Name the Layer (Useing info from spreadsheet)

( I have to do this 2000 times) - I am on # 150 right now!?!?

This is what I would like to do.

1.) Create all of my fill Layers and leave the standard name Pattern Fill 1, 2, 3 etc....

2.) Run a script that will replace the stadard name (Pattern Fill 1) with the name of the pattern that the layer is filled with.


I agree with Christoph it would be easier to create all the layers IE:-

#target photoshop
main();
function main(){
var file = File.openDialog("Please select Pat file"); 
if(file == null) return;
if(!documents.length){
   var doc = app.documents.add(UnitValue(300, "px"), UnitValue(300, "px"),72,"Patterns");
}
  file.open("r");
  file.encoding = 'BINARY';
  var str = file.read();
  file.close();
  var patterns=[];
  //Thanks to X for the regex
  var re = /(\x00\w|\x00\d)(\x00\-|\x00\w|\x00\s|\x00\d)+\x00\x00\$[-a-z\d]+/g;
  var parts = str.match(re);
  for (var i = 0; i < parts.length; i++) {
    var p = parts;
    var sp = p.replace(/\x00/g, '').split('$');
     patterns.push([[sp[0]], [sp[1]]]);  
      }
  //load pattern file
  app.load(file);
for(var a in patterns){
fillPattern(patterns[0].toString(),patterns[1].toString(),100); 
    }
};

function fillPattern(name, id, opacity) {
    activeDocument.artLayers.add();
    activeDocument.activeLayer.name = name;
    var desc6 = new ActionDescriptor();
    desc6.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('FlCn'), charIDToTypeID('Ptrn') );
        var desc7 = new ActionDescriptor();
        desc7.putString( charIDToTypeID('Nm  '), name );
        desc7.putString( charIDToTypeID('Idnt'), id);
    desc6.putObject( charIDToTypeID('Ptrn'), charIDToTypeID('Ptrn'), desc7 );
    desc6.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), opacity );
    desc6.putEnumerated( charIDToTypeID('Md  '), charIDToTypeID('BlnM'), charIDToTypeID('Nrml') );
    try{
    executeAction( charIDToTypeID('Fl  '), desc6, DialogModes.NO );
    activeDocument.activeLayer.visible=false;
    }catch(e){app.activeDocument.activeLayer.remove();}
};

c.pfaffenbichler
Community Expert
Community Expert
September 14, 2011

That is a fairly complicated – task for me at least.

But I suppose if you use xbytor’s xtools’s PatternFile.js instead of on the .pat-files in the Presets-folders on "~/Library/Preferences/Adobe Photoshop CS5 Settings/Patterns.psp" you might be able to get a list of all the loaded patterns’ names and Ids and then use regular ScriptingListener-code in a for-clause to create the corresponding Pattern Layers. (Points in the Pattern-names seem to provide a problem, though. Edit: And slashes, too.)

Otherwise it might be necessary to save the Patterns into a new .pat-file.

Edit: As you mention that the patterns are in one library anyway that’s moot.

Inspiring
September 14, 2011
As you mention that the patterns are in one library anyway that’s moot.

The patterns need to be in a .pat file so that you can use PatternFile.js to read the pattern names and ids.

You need both the names and ids in order to use them for a Fill. I don't know of anyway of getting the ids

from the runtime/presets-manager.

JGo2Author
Participating Frequently
September 16, 2011

Ok guys I do have the pattern saved to a .pat file. These patterns are images of carpet and they are labled by style-color. They are all in the same library because they are all for the same project. I can get the name and Id for each one of these, but how do I get photoshop to put the pattern name as the layer name. With out having to type up a script for each pattern. I will only be using each pattern once.

Let me explain alittle better.

Here is the proccess I am going through now. I am makeing a monster file with a Fill Pattern layer for every carpet. I have linked the pattern to the layer so when I change the canvas size the patterns will auto generate to the canvas size.

Right now these are the steps for each layer.

1.) Create new Fill Pattern layer

2.) Select the pattern that I want to use.

3.) Name the Layer (Useing info from spreadsheet)

( I have to do this 2000 times) - I am on # 150 right now!?!?

This is what I would like to do.

1.) Create all of my fill Layers and leave the standard name Pattern Fill 1, 2, 3 etc....

2.) Run a script that will replace the stadard name (Pattern Fill 1) with the name of the pattern that the layer is filled with.