Skip to main content
Lordrhavin
Inspiring
September 26, 2024
Question

How to Retrieve the Linked Object from a LinkedPageItem in InDesign

  • September 26, 2024
  • 4 replies
  • 2038 views

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>

4 replies

Participant
September 27, 2024

I dont understand what you're all talking about. Sorry.

 

You have Object-A. (for example: a group of a textframe and and Image)

 

You create Object-B as a link of Object-A. So if you change Object-A's Textframe-text, Object-B will update.

 

Now, later on, you get hold of Object-B.

 

How do ypu get Object-A if you have Object-B? They're linkt, right…? This cant be that complicated..

rob day
Community Expert
Community Expert
September 27, 2024

Hi @Lordrhavin , Look at the link object’s goToSource() method. The pageItem’s linkedPageItemOption lets you set the Link Options... for a link, which you access via the Link panel’s flyout menu in the UI.

 

For example here there are 2 linked objects, which both link to the top rectangle:

 

 

 

If I select one of the linked page items, I can get its source via goToSource and edit it like this:

 

//get the document links
var lnks = app.activeDocument.links

//a selected linked page item
var sel = app.selection[0]
var ls;

//loop thru the links and if the selection’s id and the link’s parent id match
//use goToSource which selects the source rectangle
for (var i = 0; i < lnks.length; i++){
    if (sel.id == lnks[i].parent.id) {
        lnks[i].goToSource();
        ls = app.selection[0]
    } 
};

//change the source fill color to Black and update the links
ls.fillColor= "Black";
lnks.everyItem().update();

 

 

Robert at ID-Tasker
Legend
September 27, 2024

@rob day

 

Can't check it right now - but per my screenshots on the other thread - wouldn't be enough to check if linkedPageItemOptions is valid - and then use goToSource()?

 

Then you won't have to iterate through links collection? 

 

m1b
Community Expert
Community Expert
September 26, 2024

Hi @Lordrhavin, If you are scripting, rather than SDKing, could you share the code that shows the issue?

 

I've done a fair bit of scripting Indesign and never used "linkedPageItemOptions" and I honestly don't know what it does. I did a google search and literally no script examples came up, which seems pretty strange. I wonder if you are using the wrong property? What are you trying to do? My guess is that linkedPageItemOptions aren't needed.

- Mark

Participant
September 27, 2024

As far as I understand, it is the options of the contentPlace-process. If you place content and it is not a copy but a link, those should be options set in the dialog.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html#d1e208586__d1e210442

leo.r
Community Expert
Community Expert
September 26, 2024

As far as I understand, you can't get it from LinkedPageItemOption. Try to explore the link object properties?

leo.r
Community Expert
Community Expert
September 26, 2024

p.s. the "can" in my previous reply is corrected to "can't". added for clarity.

Robert at ID-Tasker
Legend
September 26, 2024
Olivier Beltrami
Legend
September 26, 2024

@Lordrhavin 

The frames in a series of linked/chined frames are not parent of one another but rather Previous and Next frames relative to one another.

I'm not sure how this would translate to scripting, but using the SDK, finding the previous frame in a chain goes something like:

int32 mcfFirstFrameIndex = frameList->GetFrameIndex(mcf->GetUIDInFrameList(kFalse/*first*/));
if (mcfFirstFrameIndex == 0) {
// The given graphic frame contains the first frame in the frame list.
// There is no previous frame.
break;
}
// Determine the graphic frame that contains the previous kFrameItemBoss in the frame list.
InterfacePtr<ITextFrameColumn> previousTFC(frameList->QueryNthFrame(mcfFirstFrameIndex-1));
if (!previousTFC) {
break;
}
UIDRef previousGraphicFrameRef = this->GetGraphicFrameRef(previousTFC, kTrue/*isTOPFrameAllowed*/);
result = previousGraphicFrameRef;

Very best regards,

Olivier

Robert at ID-Tasker
Legend
September 26, 2024

@Olivier Beltrami

 

Are you referring to Text Containers of the Story?

 

Olivier Beltrami
Legend
September 27, 2024

@Robert at ID-Tasker Ah, srry I thought he was referring to linked/chained text frames.