Copy link to clipboard
Copied
I often find my self with PSD files that have many layers that need to be individually converted to Smart Objects. To save time I used to use this Photoshop .jsx script all the time to convert the multiple layers in to individual Smart Objects. I must have messed it up some how, or not sure if something changed with scripting in the newest version. Not sure how to fix it.
//-------------------------------------------------------------------------
function convertEachLayerToSmartObject(){
var resultLayers=new Array();
try{
var idGrp = stringIDToTypeID( "groupLayersEvent" );
var descGrp = new ActionDescriptor();
var refGrp = new ActionReference();
refGrp.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" ));
descGrp.putReference(charIDToTypeID( "null" ), refGrp );
executeAction( idGrp, descGrp, DialogModes.NO );
for (var ix=0;ix< llen; l++ ) {
app.activeDocument.activeLayer = resultLayers[l]
executeAction(stringIDToTypeID('newPlacedLayer'), undefined, DialogModes.NO);
}
return resultLayers;
}
convertEachLayerToSmartObject();
The dialogue box error I get is:
Error 15: Try without catch or finally. Line: 18 ->
Is there a better script out there for this? Or a better way to do this, without having to individually right click each layer Convert to Smart object? thank you!!
There are at least 3 different scripts for this task in this link:
Copy link to clipboard
Copied
A try-clause needs to be have a catch.
try {} catch () {}
Copy link to clipboard
Copied
There are at least 3 different scripts for this task in this link:
Copy link to clipboard
Copied
Thanks! This one works perfect:
// convert all top level layers and layer sets to smart objects.jsx
function main() {
if (!documents.length) {
alert('There are no documents open!');
} else {
processAllLayersAndSets(app.activeDocument);
}
function processAllLayersAndSets(obj) {
// Process all layers and layer sets
// Change the following 2 entries of "obj.layers" to "obj.artLayers" to exclude layer sets
for (var al = obj.layers.length - 1; 0 <= al; al--) {
app.activeDocument.activeLayer = obj.layers[al];
newPlacedLayer();
}
// Process Layer Set Layers
for (var ls = obj.layerSets.length - 1; 0 <= ls; ls--) {
processAllLayersAndSets(obj.layerSets[ls]);
newPlacedLayer();
}
}
// Convert to smart object (Cleaned AM code)
function newPlacedLayer() {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
executeAction(s2t("newPlacedLayer"), undefined, DialogModes.NO);
}
}
activeDocument.suspendHistory('Smart Objects from Layers & Sets', 'main()');
Copy link to clipboard
Copied
Haha, that codes looks familiar!
If you are dealing with many layers, you may wish to compare one of the other scripts that use Action Manager code as they may offer significant speed improvements over the standard for loop code.
Copy link to clipboard
Copied
Remove try{ chunk, then select chosen top level layers in your document and change::
for (var ix=0;ix< llen; l++ ) {
app.activeDocument.activeLayer = resultLayers[l]
to:
llen=(resultLayers=(aD=activeDocument).activeLayer.layers).length;for(l=0;l<llen;){
aD.activeLayer = resultLayers[l++]
Copy link to clipboard
Copied
we made a Photoshop plug-in that can do this. The unlimited version is 12$.
Full Version (12$):
https://exchange.adobe.com/apps/cc/c36e02fb/swift
Trial Version (Limited to 5 Actions):
https://exchange.adobe.com/apps/cc/412c1dcd/swift-trial-version
Its also a big help with getting the layers selected.