• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Convert each layer to individual smart object script not working

Participant ,
Jan 23, 2022 Jan 23, 2022

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 ->

 

2022-01-23.png

 

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!!

TOPICS
Actions and scripting

Views

770

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 23, 2022 Jan 23, 2022

Votes

Translate

Translate
Community Expert ,
Jan 23, 2022 Jan 23, 2022

Copy link to clipboard

Copied

A try-clause needs to be have a catch. 

try {} catch () {}

Votes

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
community guidelines
Community Expert ,
Jan 23, 2022 Jan 23, 2022

Copy link to clipboard

Copied

Votes

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
community guidelines
Participant ,
Jan 23, 2022 Jan 23, 2022

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()');

Votes

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
community guidelines
Community Expert ,
Jan 23, 2022 Jan 23, 2022

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.

Votes

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
community guidelines
LEGEND ,
Jan 25, 2022 Jan 25, 2022

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++]

 

Votes

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
community guidelines
Explorer ,
May 03, 2023 May 03, 2023

Copy link to clipboard

Copied

LATEST

we made a Photoshop plug-in that can do this. The unlimited version is 12$. 

08BA0551-DCF0-489E-9617-74BF2EB92DE5.png

 

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.

ACDB94BA-0EEB-49C2-9175-058DE034925B.png

Votes

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
community guidelines