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

Script to Perform Live Trace then in Illustrator Run Action... Please Help

New Here ,
Sep 02, 2010 Sep 02, 2010

Hello Everyone, I am brand new to scripting and need some help... I would like to create an inter-application javascript (.jsx) file that will perform the following steps in sequence:

1) Target Bridge CS3 and:


a) Automatically select files (thumbnails) (the names of, and path to these files never change so scripting them is no problem). Path & Files are: C:\files\1.psd, C:\files\2.psd and C:\files\3.psd.

b) Run Tools > Illustrator > Live Trace [Live Trace Dialogue Box Settings (Tracing Preset: Color 16, Save & Close Results (checked), Document Profile: "Basic RGB", Width: "576", Height: "720", Units: Pixels, Destination: "C:\files\, File Naming: Document Name + .ai)].

After Live Trace finishes, C:\files\1.ai, C:\files\2.ai and C:\files\3.ai are created.

and then....

2) Target Illustrator CS3 and:

Run my Illustrator precreated Action: "Add Border". This action adds a precreated border to the files. The action is coded with the paths and file names of the .ai files as well as saving instructions.

----------------------------------------------

To summarize:

1) In Bridge, run Live Trace on precreated .psd files

2) In Illustrator run an action on the files that were live traced

That's it. It seems straight forward when I write it out but trying to figure out how to script it is boggling my mind.

Thank you for your help!

TOPICS
Scripting
11.5K
Translate
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

Guide , Sep 04, 2010 Sep 04, 2010

OK, I've had a little time this morning to take a look at this for you and here is what I have… It is working just fine for me but you will be required to make 1 or 2 little typo changes yourself…

In line 7… You need to change the folders path string…

var traceFolder = new Folder ('~/Desktop/Live Trace/');

In line 71… You may want to change the save options to 13 for CS3 compatibility…

compatibility = Compatibility.ILLUSTRATOR13;

#target illustrator while (app.documents.length) {   app.activeDocumen

...
Translate
Community Beginner ,
Apr 16, 2012 Apr 16, 2012

Well this is where I got so far.

I changed the script that you wrote to import to single Ai file and it's working!

now I need to add the sub directories division

#target illustrator

while (app.documents.length) {

  app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);

}

var traceFolder = new Folder ('~/Desktop/Live Trace/');

var fileList = traceFolder.getFiles(/\.png$/i);

if (fileList.length > 0) {

     var ai = new Folder(traceFolder.fsName+'/AI Files');

     if (!ai.exists) ai.create();

    

     main(fileList);

    

} else {

     alert('This Folder contained NO Photoshop PNG files!');

    

}    

function main(fileObjs) {

     with (app) {

    

          var orginalUIL = userInteractionLevel;

         

          userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

         

          var fileName = fileList[0].name.slice(0, -4);         

          var docRef = documents.add(DocumentColorSpace.RGB, 576, 720);

         

          for (var i = 0; i < fileObjs.length; i++) {

         

               if (fileList instanceof File) {

              

                   

                   

                    with (docRef) {

                   

                         var thisPlace = placedItems.add();

                        

                         thisPlace.file = fileObjs;

                        

                         var thisImage = placedItems[0].trace();

                        

                         redraw();

                                                      

                         thisImage.tracing.tracingOptions.loadFromPreset('Wave');

                         thisImage.tracing.expandTracing();

                        

                         redraw();

                    }

               }

          }

          with (docRef) {

                         var aiOptions = saveAsAiFile();

                        

                         aiFilePath = new File(ai.fsName + '/' + fileName + '.ai');

                        

                         saveAs(aiFilePath, aiOptions);

                        

                         close(SaveOptions.DONOTSAVECHANGES);            

     }

     }

}

function saveAsAiFile() {

     var aiOptions = new IllustratorSaveOptions();

     with (aiOptions) {

          compatibility = Compatibility.ILLUSTRATOR12;

          compressed = true;

          embedICCProfile = true;

          embedLinkedFiles = true;

          flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;

          fontSubsetThreshold = 0;

          overprint = PDFOverprint.PRESERVEPDFOVERPRINT;

          pdfCompatible = true

     }

     return aiOptions;

}

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

it goes like this but the names(A,J,R....) are different:

~/Desktop/Live Trace/A/A 000.png

~/Desktop/Live Trace/A/A 001.png

~/Desktop/Live Trace/A/A 002.png

~/Desktop/Live Trace/J/J 000.png

~/Desktop/Live Trace/J/J 001.png

~/Desktop/Live Trace/J/J 002.png

~/Desktop/Live Trace/R/R 000.png

~/Desktop/Live Trace/R/R 001.png

~/Desktop/Live Trace/R/R 002.png


and the number of files wouldn't be always equal in all directories, Is it a problem?


Translate
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
Guru ,
Apr 16, 2012 Apr 16, 2012

Oh now I may need a rethink…

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

Oh no...

Translate
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
Guru ,
Apr 16, 2012 Apr 16, 2012

Im not saying it can't be done… Just that Im going to have to go back and swap some stuff about… What I was thinking was 360 layers in the document and all artboards sharing these ( layers are document wide not artboard ) to have a layer for every placed file Im now going to need 1000's never seen a file with this before ( eeeek ) I do hope no one has to scroll these…

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

If some one will need to scroll these it will be me

I know when you copy layers from one file to another you can check the "Paste remembers layers" option in the layers menu. after that you if you can select the layers and, again from the layers menu, you select the "Colect in new layer".

I don't know if it helps in scripting...

Translate
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
Guru ,
Apr 16, 2012 Apr 16, 2012

Those functions offered by the flyouts are NOT available to script… I have to do that… You can't set paste remember layers by script either… It help scriping no AI offers much less to work with that some of the other apps… Theres more to scripting ID's prefs than the whole of AI…

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

than let's keep it as it was.

I'll do the last part manualy.

Translate
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
Guru ,
Apr 16, 2012 Apr 16, 2012

Oh ya too late now… I've got to say it slows down here with no where near the files you have… A lot will be down to the trace complexity so test as you like… I don't know if some saves would be a good idea that could free up some memory may be… This worked with 4 sub-folders of a dozen files each… Do test with less files and let me know if it does what you want…

#target Illustrator

threeSixtyArtboards();

function threeSixtyArtboards() {

 

          var fileList, i, inFolder, subFiles;

          inFolder = Folder.selectDialog( 'Please choose your Parent Folder…?' );

 

          if ( inFolder != null ) {

 

                    fileList = Array();

                    inFiles = inFolder.getFiles();

                    if ( inFiles.length > 0 ) {

 

                              for ( i = 0; i < inFiles.length; i++ ) {

 

                                        if ( inFiles instanceof Folder ) {

 

                                                  subFiles = Folder( inFiles.fsName ).getFiles( /\.png$/i )

 

                                                  fileList.push( subFiles );

 

                                        };

                              };

 

                              placeAndTrace( fileList );

                    };

          };

};

function placeAndTrace( allFiles ) {

 

          var doc, i, j, lay, thisPlace, thisImage, uIL;

          uIL = userInteractionLevel;

         

          app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

 

          app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

 

          doc = app.documents.add(

                    DocumentColorSpace.RGB,

                    width = 720,

                    height = 576,

                    numArtboards = allFiles.length,

                    DocumentArtboardLayout.GridByCol,

                    artboardSpacing = 72,

                    artboardRowsOrCols = Math.round( Math.sqrt( allFiles.length ) )

          );

          for ( i = 0; i < allFiles.length; i++ ) {

                    doc.artboards.setActiveArtboardIndex( i );

 

                    for ( j = 0; j < allFiles.length; j++ ) {

                              lay = doc.layers.add();

 

                              lay.name = decodeURI( allFiles.name );

 

                              thisPlace = doc.placedItems.add();

                        

                              thisPlace.file = allFiles;

 

                              thisPlace.position = [ 0, 0 ];

 

                              redraw();

                        

                              thisImage = thisPlace.trace();

                        

                              redraw();

                                                      

                              thisImage.tracing.tracingOptions.loadFromPreset( 'Color 6' );

                              thisImage.tracing.expandTracing();

                        

                              redraw();

                    };

          };

          doc.layers.getByName( 'Layer 1' ).remove();

};

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

Thank You!!!

Well it works perfect!

is there a reason for the redraw(), it seems to work faster without it.

I'm working now with a very simple trace and with 1024 * 1024 pngs so it's not that slow. I'll try to figure out the saves like you say, it will probably make faster.

Thank you again!

Translate
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
Guru ,
Apr 16, 2012 Apr 16, 2012

Yep you are correct redraw() will force the GUI to refresh the window… This will slow the script down so you are free to comment/remove those. I use them so I can see where the test script is at… If the main part is OK correct number of layers and artboards then the rest is just cosmetic tinkering have fun… Don't forget to add the beep() do get back and let me know how many files you have this chew over…

Translate
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 ,
Apr 16, 2012 Apr 16, 2012

I ran this on two full folders and it's beutiful !!!

I'll run this tonight on all 22 folders and I'll let you know.

Thank you again, you made my next weeks so much easier!

Translate
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 ,
Apr 17, 2012 Apr 17, 2012

Well it was running all night (9 hours) and it seems like the saving doesn't help it to go faster.

It completed 15 folders while the first folder was done in 3 min. so I decided to stop the script.

The file is to heavy to work with and reopening it took too much time.

So I did a little mix and match between all the scripts so it will save each folder to a separate file in the main folder and close it.

It works like magic! after about an hour it Was all finished.

Here is the final script I used:

#target Illustrator

while (app.documents.length) {

  app.activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);

}

Main();

function Main() {

 

          var fileList, i, inFolder, subFiles;

          inFolder = Folder.selectDialog( 'Please choose your Parent Folder…?' );

          if ( inFolder != null ) {

 

                    fileList = Array();

                    inFiles = inFolder.getFiles();

                    if ( inFiles.length > 0 ) {

 

                              for ( i = 0; i < inFiles.length; i++ ) {

 

                                        if ( inFiles instanceof Folder ) {

 

                                                  subFiles = Folder( inFiles.fsName ).getFiles( /\.png$/i )

 

                                                  fileList.push( subFiles );

 

                                        };

                              };

                                                      

                              placeAndTrace( fileList , inFolder );

                    };

          };

};

function placeAndTrace( allFiles , inFolder) {

 

          var doc, i, j, lay, thisPlace, thisImage, uIL;

          uIL = userInteractionLevel;

          var orginalUIL = app.userInteractionLevel    

          app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

          for ( i = 0; i < allFiles.length; i++ ) {

                   

                    doc = app.documents.add(DocumentColorSpace.RGB,1024,1024);

                   

                    for ( j = 0; j < allFiles.length; j++ ) {

                              lay = doc.layers.add();

 

                              lay.name = decodeURI( allFiles.name );

 

                              thisPlace = doc.placedItems.add();

                        

                              thisPlace.file = allFiles;

                      

                              thisImage = thisPlace.trace();

                                                               

                              thisImage.tracing.tracingOptions.loadFromPreset( 'Wave' );

                              thisImage.tracing.expandTracing();

                                                      

                    };

                   

                     with (doc) {

                    

                           layers.getByName( 'Layer 1' ).remove();

                          

                           var aiOptions = saveAsAiFile();

                          

                           var fileName =  allFiles[1].name.slice(0, -10);

                          

                           aiFilePath = new File(inFolder.fsName+'/' +fileName+'.ai');

                          

                           saveAs(aiFilePath, aiOptions);

                          

                           redraw();

                          

                           close(SaveOptions.DONOTSAVECHANGES);

                          

                     }

                

                     beep() //

          };

     

      userInteractionLevel = orginalUIL;         

};

function saveAsAiFile() {

     var aiOptions = new IllustratorSaveOptions();

     with (aiOptions) {

          compatibility = Compatibility.ILLUSTRATOR12;

          compressed = true;

          embedICCProfile = true;

          embedLinkedFiles = true;

          flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;

          fontSubsetThreshold = 0;

          overprint = PDFOverprint.PRESERVEPDFOVERPRINT;

          pdfCompatible = true

     }

     return aiOptions;

}

Translate
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
Guru ,
Apr 17, 2012 Apr 17, 2012
LATEST

Glad you got it sorted… I did state earlier on that I thought you were pushing things… I would have NOT been happy if you'd sent me the result… It's Illustrator

Translate
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