Skip to main content
Inspiring
May 26, 2021
Answered

InDesign link update with new path through c++ plugin

Hi Everyone,

 

I need to set the new link path of image and update the link. But my code update the link path and it shows the Yellow highlighted modified icon in links panel.  I shown my code in below.

 

InterfacePtr<ILinkResourceStateUpdateCmdData> cmdData(cmd, UseDefaultIID());
cmdData->SetResource(*iter);
cmdData->SetDatabase(iDatabase);
cmdData->SetNotify(true);
cmdData->SetUpdateAction(ILinkResourceStateUpdateCmdData::kUpdateURI);
cmdData->SetURI(newURI);
cmdData->SetDatabaseModified(kTrue);

 

The issue is, the new link path is updated. But the image thumbnail not changed.

 

Could anyone reply me If I did anything wrong?

 

Thanks.

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Manan JoshiCorrect answer
Community Expert
June 6, 2021

Hi Manan,

 

I tried the below code snippet for RelinkLink function.

InterfacePtr<IUIDData> linkRef(this, UseDefaultIID());
if (linkRef)
{
	UID newLinkUID;
	Utils<Facade::ILinkFacade>()->RelinkLink(linkRef->GetRef(), newImageURI, kMinimalUI, newLinkUID);
}

 

I am using this keyword in getting linkRef. But Indesign quit unfortunately.

I don't know, how to successfully get the linkRef using *iter?

 

Please advise me on this issue.

 

Thanks.


Sorry did not get time before to write some test code for your use case. So the RelinkLink method works fine for me. I started with an InDesign document with a single image placed, then I used the code below to relink the image to a new PDF. The image was successfully linked and the panel was updated accordingly.

IDocument * doc = GetExecutionContextSession()->GetActiveContext()->GetContextDocument();
InterfacePtr<const ILinkManager> linkManager(doc,UseDefaultIID());
ILinkManager::QueryResult results;
LinkQuery query;
linkManager->QueryLinks(query, kIDLinkClientID, results);
for (auto linkUID: results) {
    UIDRef linkUIDRef(GetDataBase( linkManager ), linkUID);
    UID newLinkUID;
    URI newLinkPath("file:///Users/manan/Downloads/test.pdf");
    Utils<Facade::ILinkFacade>()->RelinkLink(linkUIDRef, newLinkPath, UIFlags::kSuppressUI, newLinkUID);
}

You can change the filepath to something on your machine and try.

-Manan

-Manan

8 replies

Community Expert
May 26, 2021

Did you look into RelinkLink method of ILinkFacade, looks like it could work for your case.

-Manan

Translate
-Manan
AD4003Author
Inspiring
May 26, 2021

Thanks Manan. I tried using the ReinitResource method in the code.

for (ILinkManager::QueryResult::const_iterator iter(linkQueryResult.begin()), end(linkQueryResult.end()); iter != end; ++iter)
{
	InterfacePtr<ILinkResource> iLinkResource(iDatabase, *iter ,UseDefaultIID());
	if(iLinkResource!=nil)
	{
		URI newImageURI = iLinkResource->GetURI();
		Utils<Facade::ILinkFacade>()->ReinitResource(UIDRef(iDatabase, *iter), newImageURI);
	}
}

 

Here, I am updating links one by one using loop.

But, nothing changed with invoking ReinitResource function. Still the issue not fixed. Please anyone let me know if I made any wrong in the above code.

 

Thanks.

Translate
Community Expert
May 26, 2021

Looking at your code I see that your code does not make any change in my opinion. You are assigning the URI or the *iter again to *iter so nothing changed. The resource URI should be a new one right?

Also, I suggested you to use RelinkLink instead of ReinitResource function, did you try that?

-Manan

Translate
-Manan