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 28, 2022 Jan 28, 2022

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:

martink15467522_0-1643361002594.png

this does not:

martink15467522_1-1643361036575.png

 

 

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 28, 2022 Jan 28, 2022

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...

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 28, 2022 Jan 28, 2022

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. 

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 28, 2022 Jan 28, 2022

Did you use the suggested tool?

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 28, 2022 Jan 28, 2022

Yes. As of now, i have tried this on 4 different pc-s with photoshop and still no success. 

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 28, 2022 Jan 28, 2022

Then I have no answer as it worked on mine. Maybe someone else wants to try it?

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 31, 2022 Jan 31, 2022

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?

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 31, 2022 Jan 31, 2022

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?

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 31, 2022 Jan 31, 2022

Yes, I could do it with nested embedded smart objects, but not nested linked smart objects.

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 ,
Feb 08, 2022 Feb 08, 2022

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. 

 

illukas.gif

 

 

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 ,
Feb 08, 2022 Feb 08, 2022

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.

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 ,
Feb 14, 2022 Feb 14, 2022

Can i report this as a bug? Currently it seems that only my computers are having difficulties running 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
LEGEND ,
Feb 14, 2022 Feb 14, 2022

It's not a bug but I guess something from outside, that interrupts 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 ,
Feb 18, 2022 Feb 18, 2022

Any ideas, what could it be? Antivirus? something else? Could the type of my adobe license affect these things?

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 ,
Feb 18, 2022 Feb 18, 2022

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, LumigraphicspixxxelschubserChuck Uebele.

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
Mentor ,
Feb 18, 2022 Feb 18, 2022

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?

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 ,
Feb 21, 2022 Feb 21, 2022

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. 

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
Mentor ,
Feb 21, 2022 Feb 21, 2022

🤷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;
        };
    }
}

 

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 ,
Feb 21, 2022 Feb 21, 2022

Same thing occurs. Loop breaks before all smart objects are updated. 

 

martink15467522_0-1645440673935.png

null is not an 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
Mentor ,
Feb 21, 2022 Feb 21, 2022

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;
        };
    }
}

 

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 ,
Feb 21, 2022 Feb 21, 2022

Tried this on 2021 (VM) and 2022 (desktop). same error in both

 

martink15467522_0-1645442879445.png

 

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
Mentor ,
Feb 21, 2022 Feb 21, 2022

Try the following:

  • Find the problem layer and manually select it
  • Run this code and copy the console output to notepad
    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')))
  • Open the smart object, update it manually, close the smart object
  • Leaving the selection on the same layer, run the code again and copy the console output to notepad

 

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.

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 ,
Feb 21, 2022 Feb 21, 2022

Added files. 1st is before updating, 2nd is after. Hope i got it correct.

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
Mentor ,
Feb 21, 2022 Feb 21, 2022

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.

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 ,
Feb 21, 2022 Feb 21, 2022

This is from trying with 1 layer.

 

 

 

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