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

Converting a bunch of artboards into separate Linked Smart Objects

Community Beginner ,
Sep 18, 2025 Sep 18, 2025

Hello all, 

I'm currently working on a huge file with numerous artboards. To lighten the file I'm converting each artboards into a smart object, into a linked smart object.

Since it's taking me some time to actually do it manually, I'm looking for a way to it automatedly create *linked smart objects* out of a selection. 

I'm on photoshop 2025 if that helps. 

 

Thanks for any help or clue 🙂

Arnault

TOPICS
Actions and scripting , Windows
297
Translate
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 2 Correct answers

Community Expert , Sep 18, 2025 Sep 18, 2025

@arnault_6305 

 

Try this v1.0 code. Revisions can be made if needed.

 

EDIT: 20th September, code updated to v1.1 to handle groups.

 

Note: The linked smart object will have four guides indicating the original artboard bounds, which might be useful if you have content extending beyond the artboard edges.

 

/* 
Convert Each Artboards Content to Separate Linked Smart Objects.jsx
Stephen Marsh
v1.0 - 19th September 2025: Initial release
v1.1 - 20th September 2025: Corrected the layer selection c
...
Translate
Community Expert , Sep 19, 2025 Sep 19, 2025

@arnault_6305 

 

Rather than processing all artboards, this new script only works on (multiple) selected artboards.

 

EDIT: 20th September, code updated to v1.1 to handle groups.

 

/* 
Convert Selected Artboards Content to Separate Linked Smart Objects.jsx
Stephen Marsh
v1.0 - 19th September 2025: Revised to work on selected artboards instead of all top-level layerSets
v1.1 - 20th September 2025: Corrected the layer selection code to include groups
https://community.adobe.com/t5/photoshop-ecosys
...
Translate
Adobe
Community Expert ,
Sep 18, 2025 Sep 18, 2025

I have two separate scripts that could be combined to do this. I'll look at it later when I have time.

 

So to be clear, each artboard should be retained, but the content of the artboard should be a single linked smart object.

 

Where should the linked .psb file be saved? The same folder as the main document? In a new sub folder?

 

One of the scripts:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-to-linked-smart-object/m-p...

Translate
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 Beginner ,
Sep 18, 2025 Sep 18, 2025

Hey, thank you so much.

Yes, each artboard should become a separate linked smart object. The idea is to extract the content of each artboard into its own .psb file, and then replace the artboard content in the main file with a linked smart object pointing to that .psb.

I’d like all the .psb files to be saved in a dedicated subfolder next to the main document. 

Appreciate any help if you get around to combining your scripts.

Translate
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 ,
Sep 18, 2025 Sep 18, 2025
quote

Hey, thank you so much.

Yes, each artboard should become a separate linked smart object. The idea is to extract the content of each artboard into its own .psb file, and then replace the artboard content in the main file with a linked smart object pointing to that .psb.

I’d like all the .psb files to be saved in a dedicated subfolder next to the main document. 

Appreciate any help if you get around to combining your scripts.


By @arnault_6305

 

That's doable, I have a rough version in progress, I should have something for you tomorrow.

Translate
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 Beginner ,
Sep 18, 2025 Sep 18, 2025

Oh my god! You're really a lifesaver!

I'm really looking forward to trying it.

Let me know if you need any extra details on anything regarding the .psb files.

 

Thanks a lot 

Translate
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 ,
Sep 18, 2025 Sep 18, 2025

@arnault_6305 

 

Try this v1.0 code. Revisions can be made if needed.

 

EDIT: 20th September, code updated to v1.1 to handle groups.

 

Note: The linked smart object will have four guides indicating the original artboard bounds, which might be useful if you have content extending beyond the artboard edges.

 

/* 
Convert Each Artboards Content to Separate Linked Smart Objects.jsx
Stephen Marsh
v1.0 - 19th September 2025: Initial release
v1.1 - 20th September 2025: Corrected the layer selection code to include groups
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-a-bunch-of-artboards-into-separate-linked-smart-objects/m-p/15510949
Partly based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-to-linked-smart-object/m-p/13357539
Note: The linked smart object will have four guides indicating the original artboard bounds, which might be useful if you have content extending beyond the artboard edges.
*/

#target photoshop

app.activeDocument.suspendHistory("Convert Each Artboard's Content to Separate Linked Smart Objects", "main()");

function main() {
    if (app.documents.length > 0) {
        var doc = app.activeDocument;
        var docName = doc.name.replace(/\.[^\.]+$/, '');
        var layerSets = doc.layerSets;

        for (var i = 0; i < layerSets.length; i++) {

            var group = layerSets[i];

            artboardBounds(group, doc);

            deselectAllLayers();

            var selectedCount = selectAllLayersInGroup(group);

            if (selectedCount > 0) {
                var newSOName = docName + "_" + group.name;
                convertToEmbeddedSmartObject(newSOName);
                convertToLinkedSmartObject();
            } else {
                alert("No layers found in group: " + group.name);
            }
        }

        processSavedPSBs(doc);

        app.beep();

    } else {
        alert("A document must be open to use this script!");
    }
}


///// Helper Functions /////

function selectAllLayersInGroup(group) {
    var selectedCount = 0;
    var childLayers = group.layers;
    
    for (var j = 0; j < childLayers.length; j++) {
        var layer = childLayers[j];
        
        // Select ArtLayers (regular layers)
        if (layer.typename === "ArtLayer") {
            selectLayerById(layer.id, selectedCount > 0);
            selectedCount++;
        }
        // Select LayerSets (groups/subgroups)
        else if (layer.typename === "LayerSet") {
            selectLayerById(layer.id, selectedCount > 0);
            selectedCount++;
        }
    }
    
    return selectedCount;
}

function sanitiseName(name) {
    return name.replace(/[\/\\:\*\?"<>\|]/g, "_");
}

function selectLayerById(id, add) {
    var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref);
    if (add) {
        desc.putEnumerated(stringIDToTypeID("selectionModifier"),
            stringIDToTypeID("selectionModifierType"),
            stringIDToTypeID("addToSelection"));
    }
    desc.putBoolean(charIDToTypeID("MkVs"), false);
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
}

function deselectAllLayers() {
    try {
        var idselectNone = stringIDToTypeID("selectNoLayers");
        executeAction(idselectNone, undefined, DialogModes.NO);
    } catch (e) {
        app.activeDocument.activeLayer = app.activeDocument.layers[0];
    }
}

function convertToEmbeddedSmartObject(newName) {
    try {
        var idapplyLocking = stringIDToTypeID("applyLocking");
        var desc1113 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref514 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        var idOrdn = charIDToTypeID("Ordn");
        var idTrgt = charIDToTypeID("Trgt");
        ref514.putEnumerated(idLyr, idOrdn, idTrgt);
        desc1113.putReference(idnull, ref514);
        var idlayerLocking = stringIDToTypeID("layerLocking");
        var desc1114 = new ActionDescriptor();
        var idprotectNone = stringIDToTypeID("protectNone");
        desc1114.putBoolean(idprotectNone, true);
        desc1113.putObject(idlayerLocking, idlayerLocking, desc1114);
        executeAction(idapplyLocking, desc1113, DialogModes.NO);

        var idnewPlacedLayer = stringIDToTypeID("newPlacedLayer");
        executeAction(idnewPlacedLayer, undefined, DialogModes.NO);

        app.activeDocument.activeLayer.name = sanitiseName(newName);
    } catch (e) {
        alert("Error converting to smart object: " + e.toString());
    }
}

function convertToLinkedSmartObject() {
    var doc = app.activeDocument;
    var docName = doc.name.replace(/\.[^\.]+$/, '');
    var assetsFolder = new Folder(doc.path + "/" + sanitiseName(docName) + "_Assets");
    if (!assetsFolder.exists) {
        assetsFolder.create();
    }

    var baseName = sanitiseName(doc.activeLayer.name);
    var fileName = baseName + ".psb";
    var file = new File(assetsFolder.fsName + "/" + fileName);

    var counter = 1;
    while (file.exists) {
        var suffix = "_" + ("000" + counter).slice(-3);
        fileName = baseName + suffix + ".psb";
        file = new File(assetsFolder.fsName + "/" + fileName);
        counter++;
    }

    var idplacedLayerConvertToLinked = stringIDToTypeID("placedLayerConvertToLinked");
    var desc346 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref49 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    ref49.putEnumerated(idlayer, idordinal, idtargetEnum);
    desc346.putReference(idnull, ref49);
    var idusing = stringIDToTypeID("using");
    desc346.putPath(idusing, file);
    executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);
}

function artboardBounds(group, doc) {
    var boundsLayer = group.artLayers.add();
    boundsLayer.name = "artboardBounds";
    doc.activeLayer = boundsLayer;
    var fillColor = new SolidColor();
    fillColor.rgb.red = 127;
    fillColor.rgb.green = 127;
    fillColor.rgb.blue = 127;

    doc.selection.selectAll();
    doc.selection.fill(fillColor);
    doc.selection.deselect()

    boundsLayer.opacity = 0;
    boundsLayer.fillOpacity = 0;

    boundsLayer.move(group.layers[0], ElementPlacement.PLACEBEFORE);
}

function processSavedPSBs(doc) {
    // Add four guides indicating the original artboard bounds
    try {
        var docName = doc.name.replace(/\.[^\.]+$/, '');
        var assetsFolder = new Folder(doc.path + "/" + sanitiseName(docName) + "_Assets");
        if (!assetsFolder.exists) {
            // nothing to do
            return;
        }

        var psbFiles = assetsFolder.getFiles("*.psb");

        for (var i = 0; i < psbFiles.length; i++) {
            var f = psbFiles[i];
            if (f instanceof File) {
                try {
                    var openedDoc = app.open(f);
                    var idnewGuidesFromTarget = stringIDToTypeID("newGuidesFromTarget");
                    executeAction(idnewGuidesFromTarget, undefined, DialogModes.NO);
                    app.activeDocument.activeLayer = app.activeDocument.layers["artboardBounds"];
                    app.activeDocument.activeLayer.remove();
                    openedDoc.close(SaveOptions.SAVECHANGES);

                } catch (e) {
                    // If opening fails, report the error but continue
                    alert("Error opening " + f.name + ": " + e.toString());
                }
            }
        }
    } catch (e) {
        alert("Error while opening saved .psb files: " + e.toString());
    }
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Translate
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 Beginner ,
Sep 19, 2025 Sep 19, 2025

Hello @Stephen Marsh,

I'm testing the script right now and it works wonderfully! 

Really, thank you so much!

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

@arnault_6305 

 

You're welcome!

 

Although designed for the current open document, It could also be recorded into an action for use with the Batch command.

Translate
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 Beginner ,
Sep 19, 2025 Sep 19, 2025

@Stephen Marsh 

I’ve never used the Batch function in Photoshop, so I wasn’t aware that was possible... that’s really good to know.
Not sure if I’ll need it right away, but I really appreciate you pointing it out.

Thanks again

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

@arnault_6305 - I'm curious, what's an example before/after file size for the original PSD file?

Translate
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 Beginner ,
Sep 19, 2025 Sep 19, 2025

@Stephen Marsh 

 

I've tested your script a bit more since this morning and some issues arose... but first, I'll answer your curiosity!

 

As a reference my project file had about 60 artboards with each between 10 and 30 layers (all kinds : rasterized layers, smart object, adjustments layers, shape...). Before the linked SO with only artboards the file was at about 13go. After the use of linked SO it goes down to less than 500mo. I haven't used your script on a full project yet since I already had converted every artboards into a linked SO, but I reckon it should show a similar result.

 

I have tried to emulate the use of your script on one of my project by using an old one on which i also had done the conversion manually. I've unlinked and unsmarted everything to get only the Artboards again. Unfortunately, your script doesn't work on this file for a reason I don't know. 

The error popup :

arnault_6305_0-1758285926395.png 

Translation :

Error 8800: A general Photoshop error has occurred. This function may not be available in this version of Photoshop.
Unable to execute this command because the file is not found.
Line: 147
→ executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);

 

 

When I create a new file with fresh artboards it works well! 

But it converts every artboard into a .psb, not only the selected ones (I don't know if it's an error or if it's my fault for not explaining myself good enough :'( ). The issue with that is : I probably won't wait for my Photoshop to crash to make the linked SO. Converting only a small selection of artboards is definitively something i would do.

Since your script preserve the artboards, if it takes every one on the main file I assume It would create another linked SO for each. Even the already converted ones (which also cause a small dysfonctionnement, but it's not too bad).

 

And I have a personal request, but I don't really mind not having it granted : It would be nice to be able to select the folder in which I want the .psb files to go. 

I'm sorry to bother you again with this! 

I'm really grateful for your help 

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

I can't comment on that error, it does sound like it doesn't like working on a "non-original" artboard.

 

You are indeed correct, the script is designed to loop over ALL artboards, not selected artboards.

Let me take a look at that, it was the same in the referenced link where two workflows were supported.

Translate
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 Beginner ,
Sep 19, 2025 Sep 19, 2025

@Stephen Marsh -  I've tried a few things to get it to work on my old project file.
Turns out the issue was entirely my fault... It seems the nomenclature was the fault, maybe it's too long or it's because it sometimes contain an "é" or "*" (the whole project name includes either one or both). 
I changed that with shorter names and it works now.
Also noticed that it doesn’t carry over the existing groups from the artboard into the new linked smart object.
I'm really freaking sorry ;;

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

I didn't test for groups, I'll look into the code tomorrow...

Translate
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 Beginner ,
Sep 19, 2025 Sep 19, 2025

I want to say apologize again. I was the one asking for this, and it ended up being such a weird issue just because I didn’t check the file name properly...
Really, thank you so much for your patience and help. I’m super grateful you'll take the time to build and adjust the script.

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

@arnault_6305 

 

It's all good, this is part of the "fun" of development!

 

As a native English speaker, I don't test with such accented characters. My code did try to account for layer names containing illegal filename characters.

 

I have updated both code versions to v1.1 to (hopefully) correctly handle groups and nested groups.

 

Let me know how the new versions go!

Translate
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 Beginner ,
Sep 20, 2025 Sep 20, 2025
LATEST

@Stephen Marsh 

 

I'm testing both of them right now and it seems they work!

 

I also did some troubleshooting for the nomenclature issue... turns out it was because the path name was too long (looks like there's a limit of about 260-ish characters for it to work). My folders were just way too nested! It wasn't the file name characters after all; your scripts handle those just fine.


I don't have my big file with me since I'm away for the weekend, but I'll keep you updated when I can try it on larger files.

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

@arnault_6305 

 

Rather than processing all artboards, this new script only works on (multiple) selected artboards.

 

EDIT: 20th September, code updated to v1.1 to handle groups.

 

/* 
Convert Selected Artboards Content to Separate Linked Smart Objects.jsx
Stephen Marsh
v1.0 - 19th September 2025: Revised to work on selected artboards instead of all top-level layerSets
v1.1 - 20th September 2025: Corrected the layer selection code to include groups
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-a-bunch-of-artboards-into-separate-linked-smart-objects/m-p/15510949
Partly based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/converting-to-linked-smart-object/m-p/13357539
Note: The linked smart object will have four guides indicating the original artboard bounds, which might be useful if you have content extending beyond the artboard edges.
*/

#target photoshop

app.activeDocument.suspendHistory("Convert Selected Artboard's Content to Separate Linked Smart Objects", "main()");

function main() {
    if (app.documents.length > 0) {
        var doc = app.activeDocument;
        var docName = doc.name.replace(/\.[^\.]+$/, '');

        ///// Process selected layers - from jazz-y /////
        var s2t = stringIDToTypeID;
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
        r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
        var lrs = executeActionGet(r).getList(p),
            sel = new ActionReference();

        for (var i = 0; i < lrs.count; i++) {
            sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
            (r = new ActionReference()).putIdentifier(s2t('layer'), p);
            (d = new ActionDescriptor()).putReference(s2t("target"), r);
            executeAction(s2t('select'), d, DialogModes.NO);

            var currentLayer = doc.activeLayer;

            if (isArtboard() === true) {
                artboardBounds(currentLayer, doc);

                deselectAllLayers();

                var selectedCount = selectAllLayersInGroup(currentLayer);

                if (selectedCount > 0) {
                    var newSOName = docName + "_" + currentLayer.name;
                    convertToEmbeddedSmartObject(newSOName);
                    convertToLinkedSmartObject();
                } else {
                    alert("No layers found in artboard: " + currentLayer.name);
                }
            } else {
                alert("Unexpected error: Are all selected layers artboards?");
                return;
            }
        }

        processSavedPSBs(doc);
        alert(lrs.count + " artboards processed to linked smart objects.");
        app.beep();

    } else {
        alert("A document must be open to use this script!");
    }
}


///// Helper Functions /////

function selectAllLayersInGroup(group) {
    var selectedCount = 0;
    var childLayers = group.layers;
    
    for (var j = 0; j < childLayers.length; j++) {
        var layer = childLayers[j];
        
        // Select ArtLayers (regular layers)
        if (layer.typename === "ArtLayer") {
            selectLayerById(layer.id, selectedCount > 0);
            selectedCount++;
        }
        // Select LayerSets (groups/subgroups)
        else if (layer.typename === "LayerSet") {
            selectLayerById(layer.id, selectedCount > 0);
            selectedCount++;
        }
    }
    
    return selectedCount;
}

function isArtboard() {
    // modified from a script by greless with hints from jazz-y!
    // returns true or false
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID('layer'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
        var options = executeActionGet(r);
        return options.hasKey(stringIDToTypeID('artboard')); // test for the required key
    } catch (e) {
        //alert(e);
    }
}

function sanitiseName(name) {
    return name.replace(/[\/\\:\*\?"<>\|]/g, "_");
}

function selectLayerById(id, add) {
    var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref);
    if (add) {
        desc.putEnumerated(stringIDToTypeID("selectionModifier"),
            stringIDToTypeID("selectionModifierType"),
            stringIDToTypeID("addToSelection"));
    }
    desc.putBoolean(charIDToTypeID("MkVs"), false);
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
}

function deselectAllLayers() {
    try {
        var idselectNone = stringIDToTypeID("selectNoLayers");
        executeAction(idselectNone, undefined, DialogModes.NO);
    } catch (e) {
        app.activeDocument.activeLayer = app.activeDocument.layers[0];
    }
}

function convertToEmbeddedSmartObject(newName) {
    try {
        var idapplyLocking = stringIDToTypeID("applyLocking");
        var desc1113 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref514 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        var idOrdn = charIDToTypeID("Ordn");
        var idTrgt = charIDToTypeID("Trgt");
        ref514.putEnumerated(idLyr, idOrdn, idTrgt);
        desc1113.putReference(idnull, ref514);
        var idlayerLocking = stringIDToTypeID("layerLocking");
        var desc1114 = new ActionDescriptor();
        var idprotectNone = stringIDToTypeID("protectNone");
        desc1114.putBoolean(idprotectNone, true);
        desc1113.putObject(idlayerLocking, idlayerLocking, desc1114);
        executeAction(idapplyLocking, desc1113, DialogModes.NO);

        var idnewPlacedLayer = stringIDToTypeID("newPlacedLayer");
        executeAction(idnewPlacedLayer, undefined, DialogModes.NO);

        app.activeDocument.activeLayer.name = sanitiseName(newName);
    } catch (e) {
        alert("Error converting to smart object: " + e.toString());
    }
}

function convertToLinkedSmartObject() {
    var doc = app.activeDocument;
    var docName = doc.name.replace(/\.[^\.]+$/, '');
    var assetsFolder = new Folder(doc.path + "/" + sanitiseName(docName) + "_Assets");
    if (!assetsFolder.exists) {
        assetsFolder.create();
    }

    var baseName = sanitiseName(doc.activeLayer.name);
    var fileName = baseName + ".psb";
    var file = new File(assetsFolder.fsName + "/" + fileName);

    var counter = 1;
    while (file.exists) {
        var suffix = "_" + ("000" + counter).slice(-3);
        fileName = baseName + suffix + ".psb";
        file = new File(assetsFolder.fsName + "/" + fileName);
        counter++;
    }

    var idplacedLayerConvertToLinked = stringIDToTypeID("placedLayerConvertToLinked");
    var desc346 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref49 = new ActionReference();
    var idlayer = stringIDToTypeID("layer");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    ref49.putEnumerated(idlayer, idordinal, idtargetEnum);
    desc346.putReference(idnull, ref49);
    var idusing = stringIDToTypeID("using");
    desc346.putPath(idusing, file);
    executeAction(idplacedLayerConvertToLinked, desc346, DialogModes.NO);
}

function artboardBounds(group, doc) {
    var boundsLayer = group.artLayers.add();
    boundsLayer.name = "artboardBounds";
    doc.activeLayer = boundsLayer;
    var fillColor = new SolidColor();
    fillColor.rgb.red = 127;
    fillColor.rgb.green = 127;
    fillColor.rgb.blue = 127;

    doc.selection.selectAll();
    doc.selection.fill(fillColor);
    doc.selection.deselect();

    boundsLayer.opacity = 0;
    boundsLayer.fillOpacity = 0;

    boundsLayer.move(group.layers[0], ElementPlacement.PLACEBEFORE);
}

function processSavedPSBs(doc) {
    try {
        var docName = doc.name.replace(/\.[^\.]+$/, '');
        var assetsFolder = new Folder(doc.path + "/" + sanitiseName(docName) + "_Assets");
        if (!assetsFolder.exists) {
            return;
        }

        var psbFiles = assetsFolder.getFiles("*.psb");

        for (var i = 0; i < psbFiles.length; i++) {
            var f = psbFiles[i];
            if (f instanceof File) {
                try {
                    var openedDoc = app.open(f);
                    var idnewGuidesFromTarget = stringIDToTypeID("newGuidesFromTarget");
                    executeAction(idnewGuidesFromTarget, undefined, DialogModes.NO);
                    app.activeDocument.activeLayer = app.activeDocument.layers["artboardBounds"];
                    app.activeDocument.activeLayer.remove();
                    openedDoc.close(SaveOptions.SAVECHANGES);

                } catch (e) {
                    alert("Error opening " + f.name + ": " + e.toString());
                }
            }
        }
    } catch (e) {
        alert("Error while opening saved .psb files: " + e.toString());
    }
}

 

Translate
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