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

How to Retrieve the Linked Object from a LinkedPageItem in InDesign

Participant ,
Sep 26, 2024 Sep 26, 2024

object.LinkedPageItemOption.parent does *not* get the linked object, it is just the object.

How do I get the linked object!?

 

If object-A is a link of Object-B, how do I get object-B if i have object-A?

 

<Title renamed by MOD>

TOPICS
How to , Scripting , SDK
2.2K
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
Community Expert ,
Sep 27, 2024 Sep 27, 2024

It returns the linked item not the source:

 

var sel = app.selection[0]
alert("LinkedPageOptions parent ID: " + sel.linkedPageItemOptions.parent.id + "     Selection ID: " + sel.id)

 

Screen Shot 28.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 ,
Sep 27, 2024 Sep 27, 2024
quote
        lnks[i].goToSource();

 

By @rob day

 

Unfortunately, this changes current selection...

 

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
Community Expert ,
Sep 28, 2024 Sep 28, 2024

Unfortunately, this changes current selection...

 

We have a reference to the selection, so reselect. A function might be something like this:

 

var doc = app.activeDocument;
var sel = doc.selection[0];
$.writeln(getLinkSource(doc,sel))
//returns the source object

var source = getLinkSource(doc,sel)
source.fillColor= "Black";
app.activeDocument.links.everyItem().update();

/**
* Get a selected linked page item’s source
* @ param d, the document 
* @ param sel a linked selection 
* @ return the link’s source object, 
* undefined if there is no selection or source 
* 
*/
function getLinkSource(d,sel){
    var lnks = d.links.everyItem().getElements();
    var src;
    for (var i = 0; i < lnks.length; i++){
        try { 
            if (sel.id == lnks[i].parent.id) {
                lnks[i].goToSource();
                src=app.selection[0];
                app.select(sel)
            } 
        }catch(e) {}  
    }
    return src;
}

 

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 ,
Sep 28, 2024 Sep 28, 2024
quote

We have a reference to the selection, so reselect.


By @rob day

 

Yes, I know that I can.

 

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