Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

I need a script to replace layers. PS CS5

$
0
0

Ok, let's say I need to replace layer (x) with layer (y), of course, Layer (y) is not in the composition.


(NOTE: layer (y) is a Vector Smart Layer while layer (x) is a regular layer named "Layer 4")

And yes each Layer (x) is named "Layer 4"


The Problem is ... There are 59 of layer (x) in the composition, and I need to replace each and everyone with layer (y)!


I would do it manually although it's time consuming, but there's also the problem that the PC slows down as I open the composition because it is 732MB and 900+ Layers, So I figured out the best way to do it is with a script, But unfortunately I have no idea how to type a script and when I googled it, I found 1 Script that can do so but it did not really work!

 

The one I tried appeared as so,

 

var prefix = "so_";
var assetPath = "assets/"  
var count = 0;
listLayersets(app.activeDocument);
listLayers(app.activeDocument);
var path;  
function listLayersets(pointer) {     for (var i = 0; i < pointer.layerSets.length; i++) {        var layerset = pointer.layerSets[i];        listLayers (layerset);    }}  
function listLayers(pointer) {    for (var i = 0; i < pointer.artLayers.length; i++) {        var layer = pointer.artLayers[i];        if (layer.name.indexOf(prefix) == 0) {            if (layer.kind == "LayerKind.SMARTOBJECT") {                app.activeDocument.activeLayer = layer;                replaceSO (app.activeDocument.path + "/" + assetPath + layer.name + ".psb");            }         }    }}  
function replaceSO (newFile) {          var id = stringIDToTypeID( "placedLayerReplaceContents" );    var desc = new ActionDescriptor();    var idn = charIDToTypeID("null");    desc.putPath( idn, new File(newFile));    var idp = charIDToTypeID("PgNm");    desc.putInteger(idp, 1);          executeAction(id, desc, DialogModes.NO);          return app.activeDocument.activeLayer}

 

I don't really understand most of that, but all I got was that I need to layer x to be renamed as so_layer (x) and layer (y) needed to be renamed as so_layer (y), also layer (y) was needed to be put in a folder named "assets" ,but unfortunatly I can't rename them all because they are alot and mixed up between many files and folders, not to mention the slow PC.

 

The result from a prototype file, was a faliure, no message, no nothing


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>