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

I don't see any problems. It is very strange.

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 think i can't catch the faulty layer, because the script saves and closes the document? And the error won't appear when i reopen it? Just a guess. 

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

The script should not open and save the main document, only smart objects. Does your script close the main document?

Try this option (if an error occurs during the link update, the script will not close the current document, but switch to the main one). In this case, the layer with the problematic object will remain open. 

 

#target photoshop
var doc = new AM('document'),
    lr = new AM('layer'),
    lrs = [],
    docIdx = 1;
if (len = doc.getProperty('numberOfLayers')) {
    docIdx = doc.getProperty('itemIndex')
    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.select(lrs.shift())
            if (lr.editSmartObject()) {
                if (lr.updateAllModified()) {
                    doc.closeDocument(true)
                }
                else {
                    doc.select(docIdx, true)
                }
            }
        }
    } while (lrs.length)
}

var doc = new AM('document'),
    lr = new AM('layer'),
    lrs = [],
    s2t = stringIDToTypeID;
if (len = doc.getProperty('numberOfLayers')) {
    for (var i = 1; i <= len; i++) {
        lrs.push(function () {
            (d = new ActionDescriptor()).putObject(s2t('object'), s2t('object'), lr.getProperty(null, i, true));
            return (executeAction(s2t('convertJSONdescriptor'), d).getString(s2t('json')));
        }())
    }
    $.writeln(lrs.join('\n\n'))
}

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.select = function (id, idxMode) {
        var ref = new ActionReference();
        if (idxMode) { ref.putIndex(target, id) } else { ref.putIdentifier(target, 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

Yes, my script closes the main document.

 

Your last script does not leave the problematic layer open, it still closes the main doc.

 

martink15467522_0-1645513599789.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
Contributor ,
Feb 13, 2023 Feb 13, 2023
LATEST

Running into 2023, i am still having the same issue. I tried splitting the processes into two scripts and using them in an action. One to open the smart objects and the other to close them. Even then, the first script that opens all the smart objects is not able to open all of them before the second script already starts saving and closing them. The end result is the original file and x amount of smart objects, which did not open before the other script started, being open. Maybe the cause is that i am using linked smart objects from an Illustrator file and the PC just cant process them fast enough? I am trying to this on a VM without GPU support. 

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