简体   繁体   中英

Photoshop, script to find a layer that contains a word in its layer's name

hope you guys can help me. I need a script that can find a layers name, for example if i have this layers:

  • Wood 123 Canvas
  • Wood 456 Specular
  • Wood 789 Lights

And i would like to find the layer that contains Canvas. And maybe, if its possible, change the layer's name color to green.

I found also this code i tried:

try {
(ref1 = new ActionReference()).putName(stringIDToTypeID('layer'),"Canvas"); // replace Canvas with your layer name
(desc1 = new ActionDescriptor()).putReference(stringIDToTypeID('null'), ref1)
executeAction(stringIDToTypeID('select'), desc1, DialogModes.NO);
} catch (e) {
    alert("Sorry, this layername does not exists");
}

This works great but only if the layer's name is exactly "Canvas".. and that's the problem

You can take a look at the Adobe Javascript Scripting Reference .

Looks like there is no faster way than to search for the right layers by hand:

var layers = app.activeDocument.artLayers
for (var i = 0; i < layers.length; i++) {
  if (/Canvas/.test(layers[i].name)) {
    // layers[i] name contains "Canvas"
  } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM