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

Create a document using the SDK

Community Beginner ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hi everyone,

 

I'm trying to create a document using the SDK. I found the AIDocumentListSuite, which seems to be just what I need, but when I try to create a document, it just returns the error "ENEW". The documentation just says that this means Illustrator failed to create a document, which doesn't tell me why it is not working.

 

This is my code:

			AIDocumentListSuite* AIDocumentList;
			ASErr error = message->d.basic->AcquireSuite(kAIDocumentListSuite, kAIDocumentListSuiteVersion, (const void**)&AIDocumentList);

			if ((!error) && (AIDocument != nullptr))
			{
				ai::UnicodeString	templ = ai::UnicodeString("A4");
				AIDocumentHandle	handle;

				error = AIDocumentList->New(templ, NULL, kDialogOn, &handle);

				if (!error)
				{
					error = AIDocumentList->Activate(handle, true);
					if (error)
					{
						PopupBox(&message->d, nullptr, "Can't open created document: Open a document before connecting to MSD!");
					}
					else
					{
						// Do something with the document...
					}
				}
				else
				{
					PopupBox(&message->d, nullptr, "Can't create document: Open a document before connecting to MSD!");
				}

				message->d.basic->ReleaseSuite(kAIDocumentListSuite, kAIDocumentListSuiteVersion);
				AIDocument = nullptr;
			}

Anybody has any idea on what the problem might be? Or where can I look?

 

Best regards,

Diogo

TOPICS
SDK

Views

198

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

Community Expert , Jul 25, 2022 Jul 25, 2022

Also I tested your code and the issue is with the preset name. A4 is not the valid value for preset. I am quoting portion of the function description below.

Preset names are those that appear in the New Document dialog,

such as "Mobile", "Print", and so on.

Using the value Print worked for me. In your case a dialog will be shown because you have used kDialogOn, using which you can set the other params. In case you use kDialogNone in that case you can set the params using the second argument of t

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hi @Diogo de Andrade,

You could check the PlayActionEvent method from AIActionManagerSuite with kAINewDocumentAction. A sample of it is shown in the SnippetRunner sample(file SnpDocumentActionHelper, line no 586)

-Manan

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
Guide ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Try setting the preset name to the empty string and supplying an AINewDocumentPreset struct. If Illustrator can't find "A4" it will fail. I've had situations where the presets you expect weren't available until some undisclosed point. If that works, there's your problem. I've generally found it's best to avoid using the preset name parameter in favour of the struct, so it's worth a shot.

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
Community Expert ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Also I tested your code and the issue is with the preset name. A4 is not the valid value for preset. I am quoting portion of the function description below.

Preset names are those that appear in the New Document dialog,

such as "Mobile", "Print", and so on.

Using the value Print worked for me. In your case a dialog will be shown because you have used kDialogOn, using which you can set the other params. In case you use kDialogNone in that case you can set the params using the second argument of the New method.

-Manan

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
Community Beginner ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

LATEST

Thanks Manan! That was exactly the problem... I was seeing the "A4" as a template on my Illustrator, and I didn't remember to test some of the others templates, rookie mistake!

Changing it to "Print" solved it.

 

Thanks a lot!

Diogo

 

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