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

How to Retrieve the Linked Object from a LinkedPageItem in InDesign

Participant ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

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

Views

784

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 ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

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

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 ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

quote
        lnks[i].goToSource();

 

By @rob day

 

Unfortunately, this changes current selection...

 

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

Copy link to clipboard

Copied

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

 

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

Copy link to clipboard

Copied

quote

We have a reference to the selection, so reselect.


By @rob day

 

Yes, I know that I can.

 

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