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

Scripting - Why certain Linked Smart Objects with Broken Link don't return "link" property?

Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Hello to all,

 

A quick scripting question:

Is there a way to determine which linked smart object with broken link will return link, and which won't?

 

This is the script I am running:

function s2t(str) { return stringIDToTypeID(str); }
function c2t(ch) { return charIDToTypeID(ch); }

function gather_smart_objects(){
    var doc_ref = new ActionReference();
    doc_ref.putIdentifier(s2t("document"), activeDocument.id);
    var doc_descriptor = executeActionGet(doc_ref);
    var layer_count = doc_descriptor.getInteger(s2t("numberOfLayers"));
    var nr_of_smart_linked = 0;
    var nr_of_smart_linked_with_missing_link = 0;
    for(var layer_index = 1; layer_index <= layer_count; ++layer_index){
        var layer_ref = new ActionReference();
        layer_ref.putProperty(s2t("property"), s2t("layerKind"));
        layer_ref.putIndex(s2t("layer"), layer_index);
        var layer_descriptor = executeActionGet(layer_ref);
        if(layer_descriptor.getInteger(s2t("layerKind")) == 5){
            var layer_id_ref = new ActionReference();
            layer_id_ref.putProperty(s2t("property"), s2t("layerID"));
            layer_id_ref.putIndex(s2t("layer"), layer_index);
            var layer_id_descriptor = executeActionGet(layer_id_ref);
            var layer_id = layer_id_descriptor.getInteger(s2t("layerID"));
            var action_ref = new ActionReference();
            action_ref.putIdentifier(c2t('Lyr '), layer_id);
            var action_descriptor = executeActionGet(action_ref);
            var smart_object = action_descriptor.getObjectValue(s2t("smartObject"));
            if (smart_object.hasKey(s2t("linked")) && smart_object.getBoolean(s2t("linked"))) {
                ++nr_of_smart_linked;
                if (!smart_object.hasKey(s2t("link"))) {
                    ++nr_of_smart_linked_with_missing_link;
                }
            }
        }
    }
    alert(nr_of_smart_linked);
    alert(nr_of_smart_linked_with_missing_link);
}

gather_smart_objects();

 

I have 121 linked smart objects with broken links in my psd.

 

nr_of_smart_linked evaluates to 121, 

nr_of_smart_linked_with_missing_link evaluates to 22. 

 

For this psd, I always get the same results, so it's not random, but I am lost as to understand why those 22 never give back the link.

 

Any help, even a direction in which to continue the investigation, would be much appreciated.

TOPICS
Actions and scripting , macOS

Views

292

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Please provide the sample file or a better description with screenshots to illustrate. 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

The numbers are there simply for the demonstration purposes. I have encountered this behavior in other psds that are missing smart object links. Unfortunately, I am not able to share the file in question.

 

The most important thing is that I have a clean machine, freshly installed photoshop, I have received this psd, so none of the links actually exist on my machine. That's why they are broken. And that was the intention.

 

When I run the script above, I get the result that some broken links have "link" property and others don't. That's the best way i can describe the setup. And the details are in the script code.

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

So you will not provide a sample file for testing? 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

It's not mine to be shared, in the first place.

 

Secondly, I am not able to reproduce this behavior on a consistent basis, because if I could, I would already provide the steps to reproduce the problem.

 

All I know is that this behavior doesn't occur if I just linked smart object , and then just delete(or move) the linked object from the computer. Beyond that, I am in dark.

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Without a file for testing this seems pointless to me, but hopefully someone else may be able to help you. 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

I am aware of that, and am trying to reproduce minimal sharable sample

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Why aren’t you using the boolean property stringIDToTypeID('linkMissing')? 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

"linkMissing" is the indicator that the link is broken. And it's present in every smartObject, but still, I'd like to be able to read the path that is missing, for every broken link. 

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

quote

"linkMissing" is the indicator that the link is broken. And it's present in every smartObject, but still, I'd like to be able to read the path that is missing, for every broken link. 


By @BorisT

The property is »true« or »false« depending on whether the linked file is available or not, isn’t it? 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Exactly. However, every linked smart object still stores the path to the original link, even if it's broken. Which is visible inside the photoshop. However, these three lines

 

action_ref.putIdentifier(c2t('Lyr '), layer_id);
var action_descriptor = executeActionGet(action_ref);
var smart_object = action_descriptor.getObjectValue(s2t("smartObject"));

 

simply don't retrieve the "link" property fo some of the broken linked smart objects. 

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

Those three lines do not refer to the »linked«-property, so what do you mean? 

 

Please at least post meaningful screenshots including the pertinent Panels to illustrate what you are talking about. 

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 01, 2024 Jul 01, 2024

Copy link to clipboard

Copied

quote

Exactly. 

Did you try using the value of the boolean property in an if-clause or not? 

 

Does this provide the same »faulty« result? 

function s2t(str) { return stringIDToTypeID(str); }
function c2t(ch) { return charIDToTypeID(ch); }

function gather_smart_objects(){
    var doc_ref = new ActionReference();
    doc_ref.putIdentifier(s2t("document"), activeDocument.id);
    var doc_descriptor = executeActionGet(doc_ref);
    var layer_count = doc_descriptor.getInteger(s2t("numberOfLayers"));
    var nr_of_smart_linked = 0;
    var nr_of_smart_linked_with_missing_link = 0;
    for(var layer_index = 1; layer_index <= layer_count; ++layer_index){
        var layer_ref = new ActionReference();
        layer_ref.putProperty(s2t("property"), s2t("layerKind"));
        layer_ref.putIndex(s2t("layer"), layer_index);
        var layer_descriptor = executeActionGet(layer_ref);
        if(layer_descriptor.getInteger(s2t("layerKind")) == 5){
            var layer_id_ref = new ActionReference();
            layer_id_ref.putProperty(s2t("property"), s2t("layerID"));
            layer_id_ref.putIndex(s2t("layer"), layer_index);
            var layer_id_descriptor = executeActionGet(layer_id_ref);
            var layer_id = layer_id_descriptor.getInteger(s2t("layerID"));
            var action_ref = new ActionReference();
            action_ref.putIdentifier(c2t('Lyr '), layer_id);
            var action_descriptor = executeActionGet(action_ref);
            var smart_object = action_descriptor.getObjectValue(s2t("smartObject"));
            if (smart_object.hasKey(s2t("linked")) && smart_object.getBoolean(s2t("linked"))) {
                ++nr_of_smart_linked;
                if (smart_object.getBoolean(stringIDToTypeID('linkMissing')) == true) {
/*if (!smart_object.hasKey(s2t("link"))) {*/
                    ++nr_of_smart_linked_with_missing_link;
                }
            }
        }
    }
    alert(nr_of_smart_linked);
    alert(nr_of_smart_linked_with_missing_link);
}

gather_smart_objects();

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

Hi, 

 

I forgot to add, Thank You for Your time.

 

First, to answer Your question, Yes, I have used the "linkMissing" property.

 

Second, I was able to create the .psd that produces this behavior. The steps are rather simple, the important part is to make it on the different machine to the one that You are trying to test on.

 

The steps are:

 

  1.  Create first .psd file
  2.  Create second .psd file
  3.  In the second .psd file, add first .psd using "File -> Place Linked..."
  4.  Rename or delete Your first .psd file.

 

If on the second .psd You run the script below, You will see that there will be 3 alerts, first two will say that there is 1 object each (1 smart object, 1 smart object with 'linkMissing' property set to False). The third alert will say there is no smart object with 'linkMissing' property set to False and missing 'link' property.

 

Now, I've created the provided .psd in the exact same way. And, if You download my psd, and run the script on it, the last alert will also say there is 1 smart object with 'linkMissing' property set to False and missing 'link' property.

 

 

 

 

function s2t(str) { return stringIDToTypeID(str); }
function c2t(ch) { return charIDToTypeID(ch); }

function gather_smart_objects(){
    try {
        var doc_ref = new ActionReference();
        doc_ref.putIdentifier(s2t("document"), activeDocument.id);
        var doc_descriptor = executeActionGet(doc_ref);
        var layer_count = doc_descriptor.getInteger(s2t("numberOfLayers"));
        var linked_smart_objects = 0;
        var linked_smart_objects_link_missing = 0;
        var linked_smart_objects_link_missing_no_link_property = 0;
        for (var layer_index = 1; layer_index <= layer_count; ++layer_index) {
            var layer_ref = new ActionReference();
            layer_ref.putProperty(s2t("property"), s2t("layerKind"));
            layer_ref.putIndex(s2t("layer"), layer_index);
            var layer_descriptor = executeActionGet(layer_ref);
            if (layer_descriptor.getInteger(s2t("layerKind")) == 5) {
                var layer_id_ref = new ActionReference();
                layer_id_ref.putProperty(s2t("property"), s2t("layerID"));
                layer_id_ref.putIndex(s2t("layer"), layer_index);
                var layer_id_descriptor = executeActionGet(layer_id_ref);
                var layer_id = layer_id_descriptor.getInteger(s2t("layerID"));
                var action_ref = new ActionReference();
                action_ref.putIdentifier(c2t('Lyr '), layer_id);
                var action_descriptor = executeActionGet(action_ref);
                var smart_object = action_descriptor.getObjectValue(s2t("smartObject"));
                if (smart_object.hasKey(s2t("linked")) && smart_object.getBoolean(s2t("linked"))) {
                    ++linked_smart_objects;
                    if (smart_object.getBoolean(s2t("linkMissing"))) {
                        ++linked_smart_objects_link_missing;
                        if (!smart_object.hasKey(s2t("link"))) {
                            ++linked_smart_objects_link_missing_no_link_property;
                        }
                    }
                }
            }
        }

        alert("Linked smart objects: " + linked_smart_objects);
        alert("Linked smart objects with 'linkMissing' set to True: " + linked_smart_objects_link_missing);
        alert("Linked smart objects with 'linkMissing' set to True and no 'link' property: " + linked_smart_objects_link_missing_no_link_property);
    } catch (e) {
        alert("Something went wrong. Reason: " + e);
    }
}

gather_smart_objects();
alert("Done!");

 

 

I am running all this on Mac, Photoshop in question is

 

Adobe Photoshop Version: 25.9.1 20240610.r.626 e3aae35 x64

 

Please, bear in mind that I wasn't very careful with the active object insid the script, my Photoshop only had one .psd open at all times, when running the script.

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

I appologize,

 

in my post all 

"smart object with 'linkMissing' property set to False" should say "smart object with 'linkMissing' property set to True"

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

Thanks for the sleuthing! 

I am currently busy, I hope I’ll be able to check out your file/your method for triggering the issue tomorrow. 

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 02, 2024 Jul 02, 2024

Copy link to clipboard

Copied

LATEST

I seem to be able to reproduce the issue of »link« being absent for »non-local missing linked Smart Objects«. 

 

What do you need the alias »link« for? 

Could you use stringIDToTypeID('fileReference') or stringIDToTypeID('documentID') instead? 

Votes

Translate

Translate

Report

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