Skip navigation
Currently Being Moderated

Steps to add vector path objects to AI document

Oct 5, 2009 7:02 AM

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,



Message was edited by: Davidbubu

  • Currently Being Moderated
    Oct 5, 2009 8:14 AM   in reply to DavidShulman



    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 {
            SnpDocumentActionHelper::VPB vpb;
            SnippetRunnerParameter* parameter = SnippetRunnerParameter::Instance();


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


            ai::FilePath profilesFolder;
            result = sAIFolders->FindFolder(kAIUserWritableStartupFileFolderType, false, profilesFolder);
            ai::FilePath defaultPresetFilePath = profilesFolder;
            ai::FilePath presetFilePath = parameter->GetFilePath("New Document Profile", true, defaultPresetFilePath);


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


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


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


            AIDocumentRulerUnitValue documentRulerUnit = chooser.PickDocumentRulerUnit();


            AIRasterResolution rasterResolution = chooser.PickDocumentRasterResolution();


            AIPreviewMode previewMode = chooser.PickPreviewMode();


            result = this->NewDocument(kDialogOff, vpb);
        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);


            // 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;
   = 200;
   = segment.out.h = segment.p.h;
            segment.out.v = 400;
            result = sAIPath->SetPathSegments(artHandle, i++, 1, &segment);


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


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


            // Keep path open.
            result = sAIPath->SetPathClosed(artHandle, false);
        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.




    Mark as:
  • Currently Being Moderated
    Oct 5, 2009 8:38 AM   in reply to DavidShulman

    SnippetRunner is a sample project published in the AISDK.

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






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



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points