Skip to main content
Participating Frequently
October 5, 2009
Question

Steps to add vector path objects to AI document

  • October 5, 2009
  • 1 reply
  • 1589 views

Hi to all AI gurus,

I'm novice AI developer (though generally experinced C/C++ dev) .

I have simple FileFormat plugin , my plugin can read some custom format vector file , similar to SVG , I would like to add strokes - path objects into new AI document.

As for this moment, I can read my file and have all vector data stored in memory ..

However I don't understand when exactly a new AI document has been created or how I can do this.  I've checked TextFileFormat sample in SDK but still missing something.

Desired sequence is  (having all data already prepared):

  1. Create new AI doc with specific dimensions , I have  AIDocumentSetup but how can I set width/ height , units and DPI
  2. Insert new vector coordinates == crarete new PathArt objects
  3. Redraw entire doc

thats it.

I just need some basic guidance here regarding these 3 point. Any sample code, link, would help.

Many thanks,

David

Message was edited by: Davidbubu

This topic has been closed for replies.

1 reply

Toto RoToTO
Inspiring
October 5, 2009

Hi,

for source code samples, you could have a look at SnipperRunner project!

We could find a lot of cool stuff in here!

for the first point:

here it is a sample from the sdk:

try {
        SDK_ASSERT(sAIActionManager);
        SnpDocumentActionHelper::VPB vpb;
        SnippetRunnerParameter* parameter = SnippetRunnerParameter::Instance();

        ai::UnicodeString documentName = parameter->GetString(ai::UnicodeString("Document name"), ai::UnicodeString("MyDocument"));
        vpb.SetNewDocumentName(documentName);

        ai::FilePath profilesFolder;
        result = sAIFolders->FindFolder(kAIUserWritableStartupFileFolderType, false, profilesFolder);
        aisdk::check_ai_error(result);
        ai::FilePath defaultPresetFilePath = profilesFolder;
        defaultPresetFilePath.AddComponent(ai::FilePath(ai::UnicodeString("Print.ai")));
        ai::FilePath presetFilePath = parameter->GetFilePath("New Document Profile", true, defaultPresetFilePath);
        vpb.SetNewDocumentSettingsFile(presetFilePath);

        SnpChooser chooser;
        AIDocumentColorModelValue documentColorModel = chooser.PickDocumentColorModel();
        vpb.SetNewDocumentColorModel(documentColorModel);

        ASReal documentWidth = parameter->GetReal("Document width", 612.0);
        vpb.SetNewDocumentWidth(documentWidth);

        ASReal documentHeight = parameter->GetReal("Document height", 792.0);
        vpb.SetNewDocumentHeight(documentHeight);

        AIDocumentRulerUnitValue documentRulerUnit = chooser.PickDocumentRulerUnit();
        vpb.SetNewDocumentRulerUnits(documentRulerUnit);

        AIRasterResolution rasterResolution = chooser.PickDocumentRasterResolution();
        vpb.SetNewDocumentRasterResolution(rasterResolution);

        AIPreviewMode previewMode = chooser.PickPreviewMode();
        vpb.SetNewDocumentPreviewMode(previewMode);

        result = this->NewDocument(kDialogOff, vpb);
        aisdk::check_ai_error(result);
    }
    catch (ai::Error& ex) {
        result = ex;
    }

for the second point, you could do as follow:

ASErr result = kNoErr;
    try {
        // Create new art item in the document.
        result = sAIArt->NewArt(kPathArt, kPlaceAboveAll, NULL, &artHandle);
        aisdk::check_ai_error(result);

        // Define path segments.
        AIPathSegment segment = {{0,0},{0,0},{0,0},false};   
        segment.corner = false;
        short i = 0;
       
        segment.p.h = 300;
        segment.p.v = 300;
        segment.in.v = 200;
        segment.in.h = segment.out.h = segment.p.h;
        segment.out.v = 400;
       
        result = sAIPath->SetPathSegments(artHandle, i++, 1, &segment);
        aisdk::check_ai_error(result);

        segment.p.h = 400;
        segment.p.v = 400;
        segment.in = segment.out = segment.p;
       
        result = sAIPath->SetPathSegments(artHandle, i++, 1, &segment);
        aisdk::check_ai_error(result);

        segment.p.h = 500;
        segment.p.v = 300;
        segment.in.v = 400;
        segment.in.h = segment.out.h = segment.p.h;
        segment.out.v = 200;
       
        result = sAIPath->SetPathSegments(artHandle, i++, 1, &segment);
        aisdk::check_ai_error(result);

        // Keep path open.
        result = sAIPath->SetPathClosed(artHandle, false);
        aisdk::check_ai_error(result);
    }
    catch (ai::Error& ex) {
        result = ex;
    }

why do you to redraw the document?

is there a special need?

you do not have to do that after adding a new Art in the Artwork tree.

Hope this will help you.

Regards,

Thomas.

Participating Frequently
October 5, 2009

Hi Thomas,

Thanks for the prompt response, its really helpful - will check thios right away.  I'm actually frantically reading through AI SDK...

What is a SnipperRunner, I cant find it in AI SDK. Any other place for download?

It seems I don't need to force document redraw  - AI does this internally.

Best,

David

Toto RoToTO
Inspiring
October 5, 2009

SnippetRunner is a sample project published in the AISDK.

If you have already downloaded it, you could find it, and some more in:

\Adobe_Illustrator_CS3_SDK\samplecode

\Adobe_Illustrator_CS4_SDK\samplecode

No need to redraw, let Illustrator do it for you!

Thomas.