2 Replies Latest reply on Oct 16, 2017 4:33 PM by Rick E Johnson

    DocumentList GetNthDocument fail

    Rick E Johnson Level 1

      Getting a list of all open documents without actually displaying them usually works well, although sometimes, especially after a Save As (kAISaveAsCommandPostNotifierStr), it crashes. Here's the code, which resides in a for loop. DocCount has been correctly retrieved (3) and document 0 gets handled correctly. When it comes to item 1, however, it works perfectly when just opening or closing files, but crashes with an EXC_BAD_ACCESS error in the compiler (Xcode 8 with Mac CC 2017) at Activate on item 1 after a Save As. The value of "error" returned from AI is always 0.

       

        AIErr error = kNoErr;

        ai::UnicodeString fullPathString;

        AIDocumentHandle doc = NULL;

        for (uint32_t i = 0; i < (docCount); i++) {

        error = sAIDocumentList->GetNthDocument(&doc, i);

        error = sAIDocumentList->Activate(doc, false); // error = 0 here but crashes if i>0 and just did Save As

        ai::FilePath filep;

        error = sAIDocument->GetDocumentFileSpecification(filep);

        error = sAIFilePath->GetFullPath(filep, true, fullPathString);

        std::string sFullPath = fullPathString.as_UTF8();

        if (sFullPath != "/") this->vOpenFiles.push_back(sFullPath); // save in string vector

        }

       

      Last, it activates what was/is the current doc. Am I overlooking something I should have included here?

       

      TIA -- Rick