Skip to main content
Participant
August 30, 2017
Answered

Can't open an existing .ai file - illustrator extendscript

  • August 30, 2017
  • 2 replies
  • 939 views

hi there, can you please tell me whats wrong with this code:

app.open("~/Desktop/New%20folder/1/v1.ai");

//or

app.open("~//Desktop//New%20folder//1//v1.ai");

//or

app.open("~\Desktop\New%20folder\1\v1.ai");

tried every possible way but nothing worked for me. Actually the code that i'm working on is this:

#target illustrator

var j ,  len =app.documents.length , docname;

var    aiDocumentPath = new Array();  //all the paths of the opened documents will be stored in this array

     for( j=0 ;   j<len ;  j++){

         docname = encodeURIComponent(app.documents.name) ;

             aiDocumentPath = app.documents.path+"/"+docname;

         

             }

          //all the paths stored

CloseAndOpen();

function CloseAndOpen(){         ///////////////////////////

var aiDocument ;

for(j=0 ; j<len ; j++){

    aiDocument = app.activeDocument;

aiDocument.close( SaveOptions.DONOTSAVECHANGES );

aiDocument = null;}

for(j=0 ; j<len ; j++){

alert("oppening "+aiDocumentPath);  //alerts the correct path looks something like ~/Desktop/New%20folder/1/v1.ai

app.open(aiDocumentPath)   ;

}

}    /////////////////////////////////

This topic has been closed for replies.
Correct answer Ten A

Remove escape like below and argument is File object.

app.open(File('~/Desktop/New folder/1/v1.ai'));

2 replies

Ten A
Community Expert
Ten ACommunity ExpertCorrect answer
Community Expert
August 30, 2017

Remove escape like below and argument is File object.

app.open(File('~/Desktop/New folder/1/v1.ai'));

Participant
August 30, 2017

thanks it worked!

PECourtejoie
Community Expert
Community Expert
August 30, 2017

I'm moving it to the AI scripting forum