Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get All Tables in an Indesign Document - Indesign SDK C++

New Here ,
Nov 26, 2024 Nov 26, 2024

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?

 

TOPICS
SDK
751
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 28, 2024 Nov 28, 2024

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
...
Translate
LEGEND ,
Nov 26, 2024 Nov 26, 2024

You don't go through Pages - you go through Stories. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2024 Nov 26, 2024

OK, if that's the case, how do I go through Stories?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 26, 2024 Nov 26, 2024

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. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2024 Nov 26, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 28, 2024 Nov 28, 2024

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 28, 2024 Nov 28, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 30, 2024 Nov 30, 2024

Ha! I think ITableModelList is 99.9% safe.  How many years old do you think that deprecation warning is?

 

Good points as always.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 01, 2024 Dec 01, 2024
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines