Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
From extendscript i get an error at line 69
autoupdateAllSmartObjects(app.activeDocument, stackNr); -- no such element
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Tried this. Now the script opens the first smart object and immediately throws the error
can't open smart object
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
}
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
After opening the smart object for editing use:
refresh()
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
(function(){try{/*failing task*/}catch(err){refresh(),callee()}})()
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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()}})();
Copy link to clipboard
Copied
Not entire code but probably only this line:
doc.activeLayer = curLayer;
btw. there's no saving command in the code, while closing is commented
Copy link to clipboard
Copied
Same error still. tried some other lines too and still does not work.
Copy link to clipboard
Copied
With 'by the way' part done?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Upload your .psd.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Better share a file with embedded .ai file I'm going to change to linked before try the script.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now