Skip to main content
FabSug
Participant
October 3, 2019
Answered

Javascript Export to Photoshop files not writing layers

  • October 3, 2019
  • 2 replies
  • 1892 views

Hello,

 

I've been trying to adapt an Illustrator script that can batch convert a folder of .ai files to .psd files with layers but the result is always flattened. 

 

 

var folder = Folder.selectDialog();
if (folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++) {
        var currentFile = files[i];
        app.open(currentFile);
        var activeDocument = app.activeDocument;
        var ExpFolder = Folder(currentFile.path);
    
            var fileName = activeDocument.name.split('.')[0] + ".psd";
            var destinationFile = File(ExpFolder + "/" + fileName);
            var type = ExportType.PHOTOSHOP;
            var options = new ExportOptionsPhotoshop();
            options.writeLayers = true;
            options.maximumEditability = true;
            options.antiAliasing = true;
            options.editableText = true;
            //options.imageColorSpace = ImageColorSpace.Grayscale; << not working
            options.resolution = 1200;

            activeDocument.exportFile(destinationFile, type, options);

        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
}

 

 

Also setting the imageColorSpace to Grayscale results in an error.

Doing some trial and error, it seems the ExportOptionsPhotoshop object is not getting the arguments passed down to it beside the resolution.

 

Batch Illustrator Actions with File > Export > Export As... works but I'd like to control the destination folder and file names with additional variables.

Thanks a lot in advance for your kind help !

 

Fabien

 

This topic has been closed for replies.
Correct answer renél80416020

Salut!

Pour conserver les calques (layers),le mode de colorimétrie doit être le même que celui du document RGB ou CMYK

// JavaScript Document
var folder = Folder.selectDialog();
if (folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++) {
        var currentFile = files[i];
        app.open(currentFile);
        var activeDocument = app.activeDocument;
        var ExpFolder = Folder(currentFile.path);

            var fileName = activeDocument.name.split('.')[0] + ".psd";
            var destinationFile = File(ExpFolder + "/" + fileName);
            var type = ExportType.PHOTOSHOP;
            var options = new ExportOptionsPhotoshop();
                options.imageColorSpace = ImageColorSpace.CMYK; //RGB
                options.resolution = 1200;
        activeDocument.exportFile(destinationFile, type, options);
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
}

 

Pour le reste me contacter par mail

elleere

 

2 replies

renél80416020
renél80416020Correct answer
Inspiring
October 4, 2019

Salut!

Pour conserver les calques (layers),le mode de colorimétrie doit être le même que celui du document RGB ou CMYK

// JavaScript Document
var folder = Folder.selectDialog();
if (folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++) {
        var currentFile = files[i];
        app.open(currentFile);
        var activeDocument = app.activeDocument;
        var ExpFolder = Folder(currentFile.path);

            var fileName = activeDocument.name.split('.')[0] + ".psd";
            var destinationFile = File(ExpFolder + "/" + fileName);
            var type = ExportType.PHOTOSHOP;
            var options = new ExportOptionsPhotoshop();
                options.imageColorSpace = ImageColorSpace.CMYK; //RGB
                options.resolution = 1200;
        activeDocument.exportFile(destinationFile, type, options);
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
}

 

Pour le reste me contacter par mail

elleere

 

FabSug
FabSugAuthor
Participant
October 4, 2019
Ouaah ! Merci beaucoup, elleere !! Je débute en scripting sur les applications Adobe et je n'ai vu cette information nulle part dans la doc, comment est-on censé le deviner ? J'ai l'impression d'avoir affaire à un savoir ancestral transmis à l'oral de générations en générations (dont une grande partie a semble-t-il été effacée avec la nouvelle version de ce forum). En tout cas, merci infiniment pour cette réponse !!
renél80416020
Inspiring
October 7, 2019

Il suffit de d'observer le comportement de la boîte de dialogue exporter... PSD

Tom Winkelmann
Inspiring
October 4, 2019

You have to separate every single path/shape/text to an individual layer before you save it as PSD...

FabSug
FabSugAuthor
Participant
October 4, 2019
Dear Tom, thanks a lot for your insight. I'm probably doing something wrong because even with a simple file (like two layers with one line on each one) it keeps outputing a flattened psd file. Is there a specific structure convention to follow ? Thanks again for your help !