Skip to main content
Inspiring
September 18, 2020
Answered

Using SnapshotUtilsEx with link references

  • September 18, 2020
  • 1 reply
  • 945 views

Hi,

I hope someone here can explain this to me:

I am trying to add the SnapshotUtilsEx functionality to my InDesign plugin.
This works with the following code:

 

UIDRef theItem; // this is obtained using ISpread->GetItemsOnPage();
SnapshotUtilsEx *snapshot = new SnapshotUtilsEx(theItem);

ErrorCode drawResult = kFailure;
drawResult = snapshot->Draw();

if (drawResult == kSuccess)
{
IDFile myIDFile; // this is initialized in my plugin
IPMStream *myStream = StreamUtil::CreateFileStreamWriteLazy(myIDFile, kOpenOut);

ErrorCode exportResult = kFailure;
exportResult = snapshot->ExportImageToJPEG(myStream);

myStream->Flush();
myStream->Close();
myStream->Release();
}

if (snapshot != NULL)
{
delete snapshot;
snapshot = NULL;
}

 

I studied the SDK samples for this and
this works fine, I get the generated thumbnails stored as a file.

Now my question is how can I obtain a UIDRef for the page-item so I can
get the filename from it, because that does not work. I use the following code
to obtain a filename from an image (page-item) UIDRef:

 

UID link;

// the link UID above is obtained through:
// InterfacePtr<const ILinkManager> linkMgr(documentDB, documentDB->GetRootUID(), UseDefaultIID());

IDataBase *documentDB; // ...
ISession *mySession = GetExecutionContextSession();

InterfacePtr<const ILinkResource> theLinkResource(documentDB, theLink->GetResource(), UseDefaultIID());
InterfacePtr<IK2ServiceRegistry> serviceRegistry(mySession, UseDefaultIID());

InterfacePtr<const IK2ServiceProvider> nameProvider = InterfacePtr<const IK2ServiceProvider>(serviceRegistry->QueryServiceProviderByClassID(kLinkInfoService, kLinkInfoNameProviderBoss));

InterfacePtr<ILinkInfoProvider> nameInfoService = InterfacePtr<ILinkInfoProvider>(nameProvider, UseDefaultIID());

PMString linkImageFileName = nameInfoService->GetUpdatedInfoForLink(theLink, theLinkResource, false);

 

Obtaining file-names this way throughout my plugin works fine.

For the snapshot I obtain the UIDRef as follows:

 

UIDRef theItem = kInvalidUIDRef;
InterfacePtr<IDocument> document(database, database->GetRootUID(), IID_IDOCUMENT);
InterfacePtr<ISpreadList> spreads(document, UseDefaultIID());
int32 numberOfSpreads = spreads->GetSpreadCount();
for (int32 i = 0; i != numberOfSpreads; i++)
{
UIDRef spreadUIDRef(database, spreads->GetNthSpreadUID(i));
InterfacePtr<ISpread> spread(spreadUIDRef, UseDefaultIID());
UIDRef theSpread = ::GetUIDRef(spread);

int32 numberOfPages = spread->GetNumPages();

for (int32 j = 0; j != numberOfPages; j++)
{
UID pageUID = spread->GetNthPageUID(j);
UID ownerUID = kInvalidUID;

InterfacePtr<IHierarchy> hierarchy(database, pageUID, UseDefaultIID());
ownerUID = Utils<ILayoutUtils>()->GetOwnerPageUID(hierarchy);

InterfacePtr<IMasterPage> masterPage(database, ownerUID/*pageUID*/, UseDefaultIID());
InterfacePtr<ISpread> masterSpread(database, masterPage->GetMasterSpreadUID(), UseDefaultIID());

masterSpread->GetItemsOnPage(masterPage->GetMasterSpreadPageIndex(), &itemsOnPage, kFalse, kFalse);

numberOfItems = itemsOnPage.Length();

//for (int32 k = 0; k != numberOfItems; k++)
//{
theItem = itemsOnPage.GetRef(/*k*/0);
//}
}
}

 

I can generate the snapshot just fine with the found UIDRef (theItem), but when trying to get the link-filename
with the code I described above, I get an empty-string.
I tried to walk through the IDocument -> ISpread -> IPage hierarchy and also
the IDocument -> ISpread -> IMasterPage hierarchy.
But clearly I am missing something.
My document has three pages with images on them.

I also followed the instructions found on:


https://community.adobe.com/t5/indesign/getitemsonpage-including-masters/m-p/5878142?page=1


that did not work for me.

Is it possible to get the file-name string from the "theItem" UIDRef?
Why does the UID in theItem differ from the same page-item UID found using ILinkManager?
Thanks in advance.

 

 

 

 

 

 

This topic has been closed for replies.
Correct answer Alo Lohrii

Yes, I'm aware of that.

My problem lies in this:

I get the UIDRef like this:

theItem = itemsOnPage.GetRef(/*k*/0);

(See last line of my code example).

With this UIDRef I want to get the linkresource shortname like in your example,

only this results in an empty-string.


try and find the link resource from the theItem using ILinkUtils::FindLinkResource()

UID resourceUID = Utils<ILinkUtils>()->FindLinkResource(theItem); 
InterfacePtr<ILinkResource> linkResource(database, resourceUID, UseDefaultIID());
linkResource->GetShortName(false);

 

1 reply

Alo Lohrii
Community Manager
Community Manager
September 22, 2020
InterfacePtr<IDocument> document(theItem, UseDefaultIID());
PMString documentName;
document->GetName(documentName);
Inspiring
September 22, 2020

Thanks for the reply, but I need the link-filename, not the document filename.

Alo Lohrii
Community Manager
Community Manager
September 22, 2020

Try ILinkResource::GetShortName() 

InterfacePtr<const ILinkResource> theLinkResource(documentDB, theLink->GetResource(), UseDefaultIID());
theLinkResource->GetShortName(false);
//theLinkResource->GetLongName(false);