Highlighted

Using SnapshotUtilsEx with link references

Explorer ,
Sep 18, 2020

Copy link to clipboard

Copied

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.

 

 

 

 

 

 

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

 

TOPICS
How to, SDK

Views

131

Likes

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

Using SnapshotUtilsEx with link references

Explorer ,
Sep 18, 2020

Copy link to clipboard

Copied

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.

 

 

 

 

 

 

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

 

TOPICS
How to, SDK

Views

132

Likes

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
Sep 18, 2020 0
Adobe Employee ,
Sep 22, 2020

Copy link to clipboard

Copied

InterfacePtr<IDocument> document(theItem, UseDefaultIID());
PMString documentName;
document->GetName(documentName);

Likes

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
Reply
Loading...
Sep 22, 2020 0
Explorer ,
Sep 22, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Sep 22, 2020 0
Adobe Employee ,
Sep 22, 2020

Copy link to clipboard

Copied

Try ILinkResource::GetShortName() 

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

 

Likes

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
Reply
Loading...
Sep 22, 2020 0
Explorer ,
Sep 22, 2020

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Sep 22, 2020 0
Adobe Employee ,
Sep 22, 2020

Copy link to clipboard

Copied

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

 

Likes

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
Reply
Loading...
Sep 22, 2020 0
Explorer ,
Sep 22, 2020

Copy link to clipboard

Copied

I just tested this and the ILinkResource pointer returns NULL.

Likes

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
Reply
Loading...
Sep 22, 2020 0
Explorer ,
Sep 22, 2020

Copy link to clipboard

Copied

My test was wrong: Your latest reply is the solution and it works for me now, thanks!!

Likes

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
Reply
Loading...
Sep 22, 2020 0