Copy link to clipboard
Copied
How can get child items of a PageUID?
This is my code, but childCount getting =0:
// Get the list of spreads in this document
InterfacePtr<ISpreadList> spreadList(document, UseDefaultIID());
// Iterate over all the spreads
int32 spreadCount = spreadList->GetSpreadCount();
for (int32 spreadIndex = 0; spreadIndex < spreadCount; spreadIndex++)
{
UIDRef spreadUIDRef(database, spreadList->GetNthSpreadUID(spreadIndex));
InterfacePtr<ISpread> spread(spreadUIDRef, UseDefaultIID());
ASSERT(spread);
if (!spread) {
break;
}
// Iterate over all the pages on the spread.
int32 numberOfPages = spread->GetNumPages();
for (int32 nPage = 0; nPage < numberOfPages; nPage++)
{
UID pageUID = spread->GetNthPageUID(nPage);
UIDRef pageUIDRef = UIDRef(database, pageUID);
InterfacePtr <IHierarchy> pageHierarchy(pageUIDRef, UseDefaultIID());
//Get chid items:
int32 childCount = pageHierarchy->GetChildCount();
for (int32 childIndex = 0; childIndex < childCount; childIndex++)
{
InterfacePtr<IHierarchy> child(pageHierarchy->QueryChild(childIndex));
UIDRef childUIDRef = ::GetUIDRef(child);
}
} // iterate pages in spread
} // iterate spreads
Here we would use
// Get child Items
DataBase* db = document.GetDataBase();
UIDList pageItems(db);
spread->GetItemsOnPage(pageIndexInSpread, &pageItems, kFalse);
for (int32 iitem = 0; iitem < pageItems.Length(); iitem++)
{
UIDRef itemRef(pageItems.GetRef(iitem));
// process each item here
}
Very best regards,
Olivier
Copy link to clipboard
Copied
Here we would use
// Get child Items
DataBase* db = document.GetDataBase();
UIDList pageItems(db);
spread->GetItemsOnPage(pageIndexInSpread, &pageItems, kFalse);
for (int32 iitem = 0; iitem < pageItems.Length(); iitem++)
{
UIDRef itemRef(pageItems.GetRef(iitem));
// process each item here
}
Very best regards,
Olivier
Copy link to clipboard
Copied
Yes, Thank you,
I know this way.
But Can we can get from pageUIDRef?
InterfacePtr <IHierarchy> pageHierarchy(pageUIDRef, UseDefaultIID());
I can get child from SpreadUIDRef. But pageUIDRef can't.
Copy link to clipboard
Copied
Hi @daitranthanhoa,
Page does not own the items that are present on it, they are owned by the spread. So I don't think that the IHierarchy of the page will have pageItems as its descendants(which is what you get as result), it should only lead to the spread boss if you move up the hierarchy. So I suppose the method provided by @Olivier Beltrami is the correct way to get the pageitems on a page.
-Manan