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

Script to run action on all smart objects

Community Beginner ,
Jun 03, 2022 Jun 03, 2022

Copy link to clipboard

Copied

Hi, 

 

I am brand new to scripting and I've pieced together the below from other forum posts. I am trying to open all smart objects in a document and clear guides with one click (or shortcut).

 

It is currently working when I run it with a layer selected, but I am having trouble with how to make it run for all of the layers in the document, not just the selected/active layer. I appreciate any help or suggestions!

 

if (app.activeDocument.activeLayer.kind == "LayerKind.SMARTOBJECT") {
    app.doAction("ClearGuides", "SmartObjects");
}

 

Thank you!

TOPICS
Actions and scripting , macOS

Views

300

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 , Jun 04, 2022 Jun 04, 2022

@EliseClaire – welcome to scripting!

 

Try this:

 

/*
Remove Guides From All Smart Object Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-run-action-on-all-smart-objects/td-p/12983602
Stephen Marsh, 4th June 2022 - v1.0
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

// processSOLayers function courtesy of c.pfaffenbichler
function processSOLayers(theParent) {
    
...

Votes

Translate

Translate
Adobe
LEGEND ,
Jun 03, 2022 Jun 03, 2022

Copy link to clipboard

Copied

layerUpdate();

function layerUpdate(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        var originalRulerUnits = preferences.rulerUnits;
        try{
            var docRef = activeDocument;
            for(var i = 0; i < docRef.artLayers.length; i++){
                var LayerRef = docRef.artLayers[i];
                if(LayerRef.kind == LayerKind.SMARTOBJECT){
                    //do stuff
                    }
                }
            preferences.rulerUnits = originalRulerUnits;
            app.displayDialogs = originalDialogMode;
            }
        catch(e){
            }
        }
    }

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 ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

@EliseClaire – welcome to scripting!

 

Try this:

 

/*
Remove Guides From All Smart Object Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-run-action-on-all-smart-objects/td-p/12983602
Stephen Marsh, 4th June 2022 - v1.0
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

// processSOLayers function courtesy of c.pfaffenbichler
function processSOLayers(theParent) {
    // Loop over all the layers
    for (var i = theParent.layers.length - 1; i >= 0; i--) {
        var theLayer = theParent.layers[i];
        // Apply the function to smart object layers
        if (theLayer.typename === "ArtLayer") {
            if (theLayer.kind === LayerKind.SMARTOBJECT) {
                var theVisibility = theLayer.visible;
                myDocument.activeLayer = theLayer;

                // Run the function to remove guides
                removeGuidesFromSOlayers();
                
                // Reset visibility; 
                theLayer.visible = theVisibility;
            }
            // Run the function on the smart object layers inside layerSets (implied, not explicitly defined)
        } else {
            processSOLayers(theLayer);
        }
    }
    return;

    function removeGuidesFromSOlayers() {
        app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
        var idclearAllGuides = stringIDToTypeID("clearAllGuides");
        executeAction(idclearAllGuides, undefined, DialogModes.NO);
        activeDocument.close(SaveOptions.SAVECHANGES);
    }
}

 

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 Beginner ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

LATEST

This worked perfectly!

I have some researching to do to fully understand how it works but I hope to get there.... Thank you so much!

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