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
I hope i understand you correctly. When the smart objects inside the smart objects are embedded, the script works. But when the inner smart objects are linked directly to an outer Illustrator file, the script does not work.
this works:
this does not:
Copy link to clipboard
Copied
No, before I ran script I manually open each object of first level to change embedded layers to linked .ai files. Then additionally I changed those files to others of same format with the same name to break the link. I did it to recrate your situation but as you see with last given script I was not able to reproduce the problem you have. Do what I adviced...
Copy link to clipboard
Copied
I tried. Ran a clean install of PS and script still does not work. After relinking the documents i managed to get the script working once. But after that, the same error occured as before. I am out of ideas at this point. I also tried running the script on a VM with another Photoshop, and still the same.
Copy link to clipboard
Copied
Did you use the suggested tool?
Copy link to clipboard
Copied
Yes. As of now, i have tried this on 4 different pc-s with photoshop and still no success.
Copy link to clipboard
Copied
Then I have no answer as it worked on mine. Maybe someone else wants to try it?
Copy link to clipboard
Copied
Did you try to run the script several times? I got the script working myself on one rare occasion.
What should be my next steps? How can it be, that i am using 4 different PC-s with photoshop, and the script works on none of them? Should i try direct linked smart objects, not nested smart objects perhaps?
Copy link to clipboard
Copied
I tried it once, maybe twice? Hope you find at least one other user to try it for you 😉
Regarding last sentence, didn't you earlier could do it with nested layer, but not linked?
Copy link to clipboard
Copied
Yes, I could do it with nested embedded smart objects, but not nested linked smart objects.
Copy link to clipboard
Copied
I have tried this again and again. Im gonna go with a wild guess that when vector objects are one the edge of the artboard or over it, then the script breaks. Can you try this?
https://drive.google.com/file/d/1YfGQRIiVZhM00XRXNTOrRqXuORtDTRp1/view?usp=sharing
When each artboard has an object that does not go over the edge of the artboard, the script works fine . As soon as i move an object to the edge and change the visible layer in Illustrator, the loop breaks mid script. The script then won't start working again until i run the same script broken into two parts as separate actions.
Copy link to clipboard
Copied
I put both files at end 'D:\AI' path, so 'Test.psd' smart objects could see linked 'A190.ai' file. The links were broken and the objects were red. After running the script the links were fixed while the objects turned into green. The script worked flawlessly again for me.
Copy link to clipboard
Copied
Can i report this as a bug? Currently it seems that only my computers are having difficulties running the script.
Copy link to clipboard
Copied
It's not a bug but I guess something from outside, that interrupts the script.
Copy link to clipboard
Copied
Any ideas, what could it be? Antivirus? something else? Could the type of my adobe license affect these things?
Copy link to clipboard
Copied
I never do it, but as no one showed up here and you wait enough long I call other ACP's who if willing might try to do that already I did to compare results with yours. Stephen_A_Marsh, c.pfaffenbichler, jazz-y, r-bin, Lumigraphics, pixxxelschubser, Chuck Uebele.
Copy link to clipboard
Copied
Everything works for me too. I don't see any problems.
Additionally tried various cropping options when importing objects - but couldn't get an error.
When a smart object is opened, a temporary file is created with its contents in the temp directory. You can get problems due to the antivirus, or if there are problems with the disk on which the temporary files folder is located.
Do you have the opportunity to try on another computer or in a virtual machine to rule out a problem with your specific device?
Copy link to clipboard
Copied
I have tried on a Virtual machine + 3 different PCs and still the same thing occurs. Also tried updating photoshop to latest version, but that did not help also.
Copy link to clipboard
Copied
🤷try this:
#target photoshop
var doc = new AM('document'),
lr = new AM('layer');
if (len = doc.getProperty('numberOfLayers')) {
for (var i = 1; i <= len; i++) {
if (lr.getProperty('layerSection', i, true).value != 'layerSectionContent') continue;
if (lr.hasProperty('smartObject', i, true)) {
var cur = lr.descToObject(lr.getProperty('smartObject', i, true))
if (!cur.linked) {
lr.selectLayerByIndex(i)
if (lr.editSmartObject()) {
lr.updateAllModified()
doc.closeDocument(true)
}
}
}
}
}
function AM(target) {
var s2t = stringIDToTypeID,
t2s = typeIDToStringID;
target = target ? s2t(target) : null;
this.getProperty = function (property, id, idxMode) {
r = new ActionReference();
if (property) {
property = s2t(property);
r.putProperty(s2t('property'), property);
}
id != undefined ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id)) :
r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
try { return property ? getDescValue(executeActionGet(r), property) : executeActionGet(r) } catch (e) { return null }
}
this.hasProperty = function (property, id, idxMode) {
property = s2t(property);
(r = new ActionReference()).putProperty(s2t('property'), property);
id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
: r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
try { return executeActionGet(r).hasKey(property) } catch (e) { return false }
}
this.descToObject = function (d, o) {
if (d) {
o = o ? o : {}
for (var i = 0; i < d.count; i++) {
var k = d.getKey(i)
o[t2s(k)] = getDescValue(d, k)
}
return o
}
}
this.selectLayerByIndex = function (idx) {
var ref = new ActionReference()
ref.putIndex(s2t('layer'), idx)
var desc = new ActionDescriptor()
desc.putReference(s2t('target'), ref)
desc.putBoolean(s2t('makeVisible'), false)
executeAction(s2t('select'), desc, DialogModes.NO)
}
this.editSmartObject = function () {
try {
executeAction(s2t('placedLayerEditContents'), undefined, DialogModes.NO)
return true
} catch (e) { return false }
}
this.updateAllModified = function () {
try {
executeAction(s2t('placedLayerUpdateAllModified'), undefined, DialogModes.NO)
return true
} catch (e) { return false }
}
this.closeDocument = function (save) {
save = save != true ? s2t('no') : s2t('yes');
(d = new ActionDescriptor()).putEnumerated(s2t('saving'), s2t('yesNo'), save);
executeAction(s2t('close'), d, DialogModes.NO)
}
function getDescValue(d, p) {
switch (d.getType(p)) {
case DescValueType.OBJECTTYPE: return { type: t2s(d.getObjectType(p)), value: d.getObjectValue(p) };
case DescValueType.LISTTYPE: return d.getList(p);
case DescValueType.REFERENCETYPE: return d.getReference(p);
case DescValueType.BOOLEANTYPE: return d.getBoolean(p);
case DescValueType.STRINGTYPE: return d.getString(p);
case DescValueType.INTEGERTYPE: return d.getInteger(p);
case DescValueType.LARGEINTEGERTYPE: return d.getLargeInteger(p);
case DescValueType.DOUBLETYPE: return d.getDouble(p);
case DescValueType.ALIASTYPE: return d.getPath(p);
case DescValueType.CLASSTYPE: return d.getClass(p);
case DescValueType.UNITDOUBLE: return (d.getUnitDoubleValue(p));
case DescValueType.ENUMERATEDTYPE: return { type: t2s(d.getEnumerationType(p)), value: t2s(d.getEnumerationValue(p)) };
default: break;
};
}
}
Copy link to clipboard
Copied
Same thing occurs. Loop breaks before all smart objects are updated.
null is not an object
Copy link to clipboard
Copied
Perhaps when updating an object, an indexing shift occurs. Let's try to abandon the use of indexes and move on to unique identifiers:
#target photoshop
var doc = new AM('document'),
lr = new AM('layer'),
lrs = [];
if (len = doc.getProperty('numberOfLayers')) {
for (var i = 1; i <= len; i++) {
if (lr.getProperty('layerSection', i, true).value != 'layerSectionContent') continue;
if (lr.hasProperty('smartObject', i, true)) {
var cur = lr.descToObject(lr.getProperty('smartObject', i, true))
if (!cur.linked) lrs.push(lr.getProperty('layerID', i, true))
}
}
do {
for (var i = 0; i < lrs.length; i++) {
lr.selectLayerById(lrs.shift())
if (lr.editSmartObject()) {
lr.updateAllModified()
doc.closeDocument(true)
}
}
} while (lrs.length)
}
function AM(target) {
var s2t = stringIDToTypeID,
t2s = typeIDToStringID;
target = target ? s2t(target) : null;
this.getProperty = function (property, id, idxMode) {
r = new ActionReference();
if (property) {
property = s2t(property);
r.putProperty(s2t('property'), property);
}
id != undefined ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id)) :
r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
try { return property ? getDescValue(executeActionGet(r), property) : executeActionGet(r) } catch (e) { return null }
}
this.hasProperty = function (property, id, idxMode) {
property = s2t(property);
(r = new ActionReference()).putProperty(s2t('property'), property);
id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
: r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
try { return executeActionGet(r).hasKey(property) } catch (e) { return false }
}
this.descToObject = function (d, o) {
if (d) {
o = o ? o : {}
for (var i = 0; i < d.count; i++) {
var k = d.getKey(i)
o[t2s(k)] = getDescValue(d, k)
}
return o
}
}
this.selectLayerById = function (id) {
var ref = new ActionReference()
ref.putIdentifier(s2t('layer'), id)
var desc = new ActionDescriptor()
desc.putReference(s2t('target'), ref)
desc.putBoolean(s2t('makeVisible'), false)
executeAction(s2t('select'), desc, DialogModes.NO)
}
this.editSmartObject = function () {
try {
executeAction(s2t('placedLayerEditContents'), undefined, DialogModes.NO)
return true
} catch (e) { return false }
}
this.updateAllModified = function () {
try {
executeAction(s2t('placedLayerUpdateAllModified'), undefined, DialogModes.NO)
return true
} catch (e) { return false }
}
this.closeDocument = function (save) {
save = save != true ? s2t('no') : s2t('yes');
(d = new ActionDescriptor()).putEnumerated(s2t('saving'), s2t('yesNo'), save);
executeAction(s2t('close'), d, DialogModes.NO)
}
function getDescValue(d, p) {
switch (d.getType(p)) {
case DescValueType.OBJECTTYPE: return { type: t2s(d.getObjectType(p)), value: d.getObjectValue(p) };
case DescValueType.LISTTYPE: return d.getList(p);
case DescValueType.REFERENCETYPE: return d.getReference(p);
case DescValueType.BOOLEANTYPE: return d.getBoolean(p);
case DescValueType.STRINGTYPE: return d.getString(p);
case DescValueType.INTEGERTYPE: return d.getInteger(p);
case DescValueType.LARGEINTEGERTYPE: return d.getLargeInteger(p);
case DescValueType.DOUBLETYPE: return d.getDouble(p);
case DescValueType.ALIASTYPE: return d.getPath(p);
case DescValueType.CLASSTYPE: return d.getClass(p);
case DescValueType.UNITDOUBLE: return (d.getUnitDoubleValue(p));
case DescValueType.ENUMERATEDTYPE: return { type: t2s(d.getEnumerationType(p)), value: t2s(d.getEnumerationValue(p)) };
default: break;
};
}
}
Copy link to clipboard
Copied
Tried this on 2021 (VM) and 2022 (desktop). same error in both
Copy link to clipboard
Copied
Try the following:
var s2t = stringIDToTypeID;
(r = new ActionReference()).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
(d = new ActionDescriptor()).putObject(s2t('object'), s2t('object'), executeActionGet(r));
$.writeln(executeAction(s2t('convertJSONdescriptor'), d).getString(s2t('json')))
Post both console outputs. This will help to find differences in the state of the layer before and after the update.
UPD: the problem is most likely not in the layer on which the script stumbles, but in the one preceding it. For simplicity, leave only 1 layer in the document that you're having trouble with. If the script works without errors with one layer, leave 2 and get data for both.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I see that the content of the layer has changed, but everything is fine with the layer attributes. Is this the exact layer where the script left off? Try to get the data on the layer that it processed last before the error occurred in the same way.
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now