Copy link to clipboard
Copied
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.
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 re
...
Copy link to clipboard
Copied
Did you look into RelinkLink method of ILinkFacade, looks like it could work for your case.
-Manan
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I have not yet attempted to use the RelinkLink function.
I'm sorry Manan. I missed to add this line in my previous comment before the ReinitResource function. I changed the scheme name for the link.
newImageURI.SetComponent(URI::kScheme, targetScheme);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It works very well. Thank you Manan.
Copy link to clipboard
Copied
Hi Manan,
Could you help me to fixing this issue. Please correct me if I did anything wrong in the adobe code.
Thanks.