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

DocumentList GetNthDocument fail

Engaged ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

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

TOPICS
SDK

Views

417

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
community guidelines

correct answers 1 Correct answer

Advocate , Oct 16, 2017 Oct 16, 2017

Sounds like the sort of thing that happens when you are not in the correct plugin context, but if the code is called in response to a notifier message the context should be set correctly.

What is the value of doc when it crashes, is it NULL?

You could try the old "set a zero timer" trick so your code is called after Illustrator has finished whatever it was doing.

Votes

Translate

Translate
Adobe
Advocate ,
Oct 16, 2017 Oct 16, 2017

Copy link to clipboard

Copied

Sounds like the sort of thing that happens when you are not in the correct plugin context, but if the code is called in response to a notifier message the context should be set correctly.

What is the value of doc when it crashes, is it NULL?

You could try the old "set a zero timer" trick so your code is called after Illustrator has finished whatever it was doing.

Votes

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
community guidelines
Engaged ,
Oct 16, 2017 Oct 16, 2017

Copy link to clipboard

Copied

LATEST

Thank you (again) LeoTaro! The zero timer trick worked. Or at least I can't make it crash again. All the best, my friend -- Rick

Votes

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
community guidelines