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

Update all linked smart objects CC2019 script not working in CC2020 and 2021

Contributor ,
Jan 21, 2022 Jan 21, 2022

Hello!

 

I am trying to use the following script to update all linked smart objects.  https://stackoverflow.com/questions/62280806/photoshop-cc2019-auto-update-all-linked-smart-objects-i...

 

But the script does not seem to be working in 2020 and 2021. It just closes the file. 

Either something is wrong with my layer structure, or is the script doing something wrong. Maybe anyone can give some advice on solving this?

 

 

 

TOPICS
Actions and scripting , Windows
5.6K
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
Adobe
Contributor ,
Jan 21, 2022 Jan 21, 2022

From extendscript i get an error at line 69

 

autoupdateAllSmartObjects(app.activeDocument, stackNr);  -- no such element

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
People's Champ ,
Jan 21, 2022 Jan 21, 2022

I didn't go into the script and didn't check,

but try replacing the line

app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));

with this code

var doc0 = app.activeDocument;
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
if (doc0 != app.activeDocument) { alert("can't open smart object"); throw("error"); }

 

And also in the same function replace the line 

app.activeDocument.close(SaveOptions.SAVECHANGES);

with this

app.activeDocument.close(SaveOptions.SAVECHANGES);
app.activeDocument = doc0;

 

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
Contributor ,
Jan 23, 2022 Jan 23, 2022

Tried this. Now the script opens the first smart object and immediately throws the error 

can't open smart object

 

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
Contributor ,
Jan 23, 2022 Jan 23, 2022

One way i got my script working was using your answer without 

 if (doc0 != app.activeDocument) { alert("can't open smart object"); throw("error"); }

and removing all smart objects from groups inside my 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
Contributor ,
Jan 24, 2022 Jan 24, 2022

I tried to create my own script, but it updates the smart objects randomly, does not update all of them and then closes the file. 

#target Photoshop
var doc = activeDocument;
var curLayer
goThroughLayers (doc);

function goThroughLayers(parentLayer){
    for(var i=0;i<parentLayer.layers.length;i++){
        curLayer = parentLayer.layers[i];
               doc.activeLayer = curLayer;            
        
        if(curLayer.typename =='LayerSet')
            {
            goThroughLayers (curLayer)
            }
        
    else{            
             if(curLayer.kind == 'LayerKind.SMARTOBJECT'){                       
                                 
                    //Open smart object layer
                    app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
                    //update smart object layer content
                    app.runMenuItem(stringIDToTypeID('placedLayerUpdateAllModified'));                           
                     //save smart layer content
                     app.activeDocument.close(SaveOptions.SAVECHANGES);      
                    }            
                }   
                     
            }
           
        }
    
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
People's Champ ,
Jan 25, 2022 Jan 25, 2022
quote

One way i got my script working was using your answer without 

 if (doc0 != app.activeDocument) { alert("can't open smart object"); throw("error"); }

and removing all smart objects from groups inside my files.


By @martink15467522

 

There's a logical error there. You need to use "==" instead of  "!=".
 
Also there was no need to reorganize the structure of layers or 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
Contributor ,
Jan 25, 2022 Jan 25, 2022

It does not matter, which logic i use, it still alerts the error immediately. My own script sample works, but i think it has to be async, because the script does not wait until a smart object is open as a separate document. 

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

After opening the smart object for editing use:

refresh()
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
Contributor ,
Jan 26, 2022 Jan 26, 2022

Tried it. Script almost works now, but still too fast. For example, if I have 12 linked smart objects in a psd, it manages to update 8, and the last 4 do not. How many refreshes would it be reasonable to use? more than one is too 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
LEGEND ,
Jan 26, 2022 Jan 26, 2022

 

(function(){try{/*failing task*/}catch(err){refresh(),callee()}})()

 

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
Contributor ,
Jan 26, 2022 Jan 26, 2022

Not sure where should i use this? It seems your function activates refresh only if there is an error? I forgot to add, that these smart objects are nested ( linked smart object inside embedded smart object), could this be an issue?

 

What i want the script to do. 

1. Loop through all layers

2. If a layer is a smart object, open that smart object > update modified content > save and close.

 

What my script currently does:

1. Loops through layers.

2. First 8(for example) smart objects are opened, updated and closed correctly, but since the 9th is a bigger document, Photoshop does not get it open before the loop already tries to save it. this causes the script to save and close the main file. 

 

if i use activeDocument = doc; instead of  app.activeDocument.close(SaveOptions.SAVECHANGES); the script manages to update the first 8 objects and manages to open all the others, but not update them. 

 

 

 

 

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
LEGEND ,
Jan 26, 2022 Jan 26, 2022

Inside of commented part you may activate document that perhaps is not set yet. Check how your script works in slower mode: Step by Step Playback options of dropdown Action menu.

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
Contributor ,
Jan 26, 2022 Jan 26, 2022

Step by step playback does nothing when i use a script from an action. I tried Extendscript step by step and found nothing new

I tried changing my code with your function, but still the same happens. Photoshop opens the documents too fast, and does not update linked smart objects in all the files.

Not sure about the document that is not set yet part.

#target photoshop
var doc = activeDocument;
var curLayer;

(function(){try{
 goThroughLayers (doc);

function goThroughLayers(parentLayer){
    for(var i=0;i<parentLayer.layers.length;i++){
        curLayer = parentLayer.layers[i];
        doc.activeLayer = curLayer;         
          
        if(curLayer.typename =='LayerSet'){
            goThroughLayers (curLayer)
            }
        else{            
            if(curLayer.kind == 'LayerKind.SMARTOBJECT'){
                //Open smart object layer                 
               app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));                         
               //update smart object layer content               
               app.runMenuItem(stringIDToTypeID('placedLayerUpdateAllModified'));                    
               //save smart layer content
                activeDocument = doc;                
             //app.activeDocument.close(SaveOptions.SAVECHANGES);       
             }
        }//end if
    }//end else
}//end loop
//end functin      
}catch(err){refresh(),callee()}})();

 

 

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
LEGEND ,
Jan 26, 2022 Jan 26, 2022

Not entire code but probably only this line:

 

doc.activeLayer = curLayer;

 

btw. there's no saving command in the code, while closing is commented

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
Contributor ,
Jan 26, 2022 Jan 26, 2022

Same error still. tried some other lines too and still does not work.

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
LEGEND ,
Jan 26, 2022 Jan 26, 2022

With 'by the way' part done?

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
Contributor ,
Jan 27, 2022 Jan 27, 2022

Yes, even with the btw part done.

Tried some other options and found a workaround. It works, but it's not the best.

I split the opening and closing of smart objects to two different scripts. Also added a script event listener for file open to also update linked smart objects, because just the script was not fast enough. 

 

I use 2 different actions to activate these scripts. Tried putting 2 scripts under the same action, but the same error occurs: photoshop is not able to open all smart objects before the second script starts. Even if I set playback to pause.

 

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
LEGEND ,
Jan 27, 2022 Jan 27, 2022

Upload your .psd.

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
Contributor ,
Jan 27, 2022 Jan 27, 2022
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
LEGEND ,
Jan 27, 2022 Jan 27, 2022

The smart objects contains linked .ai files with the paths I have of course no access to.

 

Btw which exact full code you want us to try it on the provided psd file, any of posted?

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
Contributor ,
Jan 27, 2022 Jan 27, 2022

I think you can relink it to any ai file with multiple artboards for testing. all the links are from the same AI file, but different artboards.

Code is following:

#target photoshop
var doc = activeDocument;
var curLayer;
goThroughLayers (doc);

function goThroughLayers(parentLayer){
    for(var i=0;i<parentLayer.layers.length;i++){
        curLayer = parentLayer.layers[i];
        doc.activeLayer = curLayer;     
          if(curLayer.typename =='LayerSet' ){
            goThroughLayers (curLayer)
            }
        else{            
            if(curLayer.kind == 'LayerKind.SMARTOBJECT'){
                //Open smart object layer                 
               app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));                         
               //update smart object layer content               
               app.runMenuItem(stringIDToTypeID('placedLayerUpdateAllModified'));                    
               //save smart layer content
                //activeDocument = doc; 
                app.activeDocument.close(SaveOptions.SAVECHANGES);                  
               }
        }//end if
    }//end else
}//end loop
//end functin

 

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
LEGEND ,
Jan 27, 2022 Jan 27, 2022

Better share a file with embedded .ai file I'm going to change to linked before try 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
Contributor ,
Jan 27, 2022 Jan 27, 2022
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
LEGEND ,
Jan 27, 2022 Jan 27, 2022

I exported inner objects, saved mine file and reopened. Then replaced exported files by others with same name and ran script. It worked on all to the end. Perhaps you should try:

How and when to use the Creative Cloud Cleaner tool | Advanced steps

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