Copy link to clipboard
Copied
How would I iterate through every page in an Indesign document and build a list of the tables in each page, using the Indesign C++ SDK?
You'd have to get the stories in the document, iterate through them, and get all the tables on each story.
Each story has a list of story threads. Each table is a story thread (though not every story thread is a table). So go through all the threads in a story, check if it's a table, and if it add it to the list. Read the API docs for more info on story models, story threads, and tables.
Here's sample code:
/**
* @brief Retrieves all table models in the specified document.
*
* This function i
...
Copy link to clipboard
Copied
You don't go through Pages - you go through Stories.
Copy link to clipboard
Copied
OK, if that's the case, how do I go through Stories?
Copy link to clipboard
Copied
I'm sorry but I'm not plug-in writer.
But, if I may - first, learn how to use InDesign and learn scripting - DOM - otherwise, you'll be constantly hitting the wall - as you have no idea about InDesign's internal structure.
Copy link to clipboard
Copied
I'm well aware of the DOM. I just got terms mixed up momentarily.
If anyone here can speak on the C++ side of things, I'm all ears.
Copy link to clipboard
Copied
You'd have to get the stories in the document, iterate through them, and get all the tables on each story.
Each story has a list of story threads. Each table is a story thread (though not every story thread is a table). So go through all the threads in a story, check if it's a table, and if it add it to the list. Read the API docs for more info on story models, story threads, and tables.
Here's sample code:
/**
* @brief Retrieves all table models in the specified document.
*
* This function iterates through all user-accessible stories in the given document
* and collects the UID references of all table models found within those stories.
*
* @Param in_DocUIDRef The UID reference of the document to search for table models.
* @Param out_TableUIDs A vector to store the UID references of the found table models.
* @Return ErrorCode Returns kSuccess if all table models are successfully retrieved, otherwise kFailure.
*/
ErrorCode GetAllTableModelsOnDocument(const UIDRef& in_DocUIDRef, UIDRefVector& out_TableUIDs) const
{
ErrorCode status = kFailure;
do {
// Get the story list interface for the document
InterfacePtr<IStoryList> storyList(in_DocUIDRef, UseDefaultIID());
if (storyList == nil)
{
ASSERT(storyList);
break;
}
// Get the database associated with the document
IDataBase* db = in_DocUIDRef.GetDataBase();
if (db == nil)
{
ASSERT(db);
break;
}
// Get the number of user-accessible stories in the document
const int32 numStories = storyList->GetUserAccessibleStoryCount();
status = kSuccess;
// Iterate through each story and collect table models
for (int32 index = 0; index < numStories; ++index)
{
UIDRef curStory(storyList->GetNthUserAccessibleStoryUID(index));
// Retrieve all tables in the current story
if (GetAllTablesInStory(curStory, out_TableUIDs) != kSuccess)
{
ASSERT_FAIL("Could not get tables from story!");
status = kFailure;
break;
}
}
} while (kFalse);
return status;
}
/**
* @brief Retrieves all table models in the specified text story.
*
* This function iterates through the text story threads in the given text story
* and collects the UID references of all table models found within those threads.
*
* @Param in_TextStoryRef The UID reference of the text story to search for table models.
* @Param out_TableModelUIDs A vector to store the UID references of the found table models.
* @Return ErrorCode Returns kSuccess if all table models are successfully retrieved, otherwise kFailure.
*/
ErrorCode GetAllTablesInStory(const UIDRef& in_TextStoryRef, UIDRefVector& out_TableModelUIDs) const
{
ErrorCode status = kFailure;
do {
// Get the database associated with the text story
IDataBase* db = in_TextStoryRef.GetDataBase();
if (db == nil)
{
ASSERT(db);
break;
}
// Get the story thread hierarchy interface for the text story
InterfacePtr<ITextStoryThreadDictHier> storyThreadHier(in_TextStoryRef, UseDefaultIID());
if (storyThreadHier == nil)
{
ASSERT(storyThreadHier);
break;
}
UID nextUID = in_TextStoryRef.GetUID();
// Iterate through the story threads and collect table models
do {
if (nextUID != kInvalidUID)
{
// Get the table model interface for the current UID
InterfacePtr<ITableModel> tableModel(db, nextUID, UseDefaultIID());
// If it's a table model, add it to the output vector
if (tableModel != nil)
{
out_TableModelUIDs.push_back(UIDRef(db, nextUID));
}
}
nextUID = storyThreadHier->NextUID(nextUID);
} while (nextUID != kInvalidUID);
status = kSuccess;
} while (kFalse);
return status;
}
Copy link to clipboard
Copied
ITableModelList is still around despite an old deprecation warning that also confirms ITextStoryThreadDictHier as new scheme.
On the other hand ITableModelList could be quicker as it is persistent.
Tough choice.
Copy link to clipboard
Copied
Ha! I think ITableModelList is 99.9% safe. How many years old do you think that deprecation warning is?
Good points as always.
Copy link to clipboard
Copied
My guess was a farewell/todo message from maybe 2008. Let me see:
The comment is already present in my oldest copy of the SDK, that is version 2.x with a $DateTime: 2002/08/27 .
Never touch a running system.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now