2

I have an illustrator file that contains 4 layers with each its own word and 180 more layers. I want to make combinations of the 4 layers with the 180 layers.

I'm currently trying to write the code with the information I found on the internet. I put every layer with the name "Layer" in a new array called fabriks. What I don't know is how to activate the layer "make", "think", "search", "print", and "makerspace" one by one to be exported with the layers in the fabriks array. I created a second array "rooms" to put the 4 words in there.

The code doesn't fully work. It exports the images but some layers overlap each other and sometimes only one layer from the fabriks array is visible but not from the rooms array.

var outpath = "~/Desktop/FABRIK MAKERSPACE";
var doc = app.activeDocument;

var makerspace = app.activeDocument.layers.getByName("Makerspace");
var make = app.activeDocument.layers.getByName("Maakt");
var think = app.activeDocument.layers.getByName("Denkt");
var search = app.activeDocument.layers.getByName("Zoekt");
var print = app.activeDocument.layers.getByName("Print");

var targetLayerName;
var layerName = "Layer";
var fabriks = Array();
var layers = doc.layers;
var rooms = Array();

rooms.push(makerspace);
rooms.push(make);
rooms.push(think);
rooms.push(search);
rooms.push(print);

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

    targetLayerName = new String(layers[i].name);

    if (targetLayerName == layerName) {
        fabriks.push(layers[i]);
    }

    layers[i].visible = false;
}
   
var counter = fabriks.length;

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

    var roomsName = String(rooms[i].name);
    rooms[i].visible = true;

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

        fabriks[i].visible = true;

        var fname = outpath + "FABRIK_" + roomsName + "_" + counter;
        var f = new File(fname + '.png');
        var exportOptions = new ExportOptionsPNG8(); // or PNG24

        exportOptions.colorCount = 200;
        exportOptions.transparency = true;

        app.activeDocument.exportFile(f, ExportType.PNG8, exportOptions);

        for (var j = 0; j < fabriks[i].length - 1; j++) {
            fabriks[i].visible = false;
        }

        rooms[i].visible = false;
    }
    counter--;
}

enter image description here

Thank you

11
  • Someone you've never seen before approached you and says..... "I tried to create a logo but I'm no designer. Can someone help me out by creating a logo for me?" -- Sounds kind of bad when you look a the question from a different angle, doesn't it? – Scott Jan 3 at 18:56
  • It's not about creating a logo. I already created a logo and nobody needs to help me to create one. Sorry, it came off wrong. Let me rephrase it then. I want to export Layer 1 to 180 with Layer "Name 1", Layer "Name 2", Layer "Name 3", and Layer "Name 4". So When exporting I want combinations Layer 1 + Name 1, Layer 1 + Name 2, ... Layer 180 + Name 1, Etc – CynniDC Jan 3 at 19:09
  • You're asking someone to provide you a script. How is that different than someone asking you to provide a logo free of charge? Work is work. I don't mean to seem unwelcoming in any way. But requests for free work are not what this site is about. We are here to help when you are struggling, not complete something for you. Please share what you have tried and where you are having difficulty. – Scott Jan 3 at 19:40
  • Okay, I understand. I just saw other people do the same thing. That's why I thought I could ask this question here. I will try to look further online. – CynniDC Jan 3 at 20:00
  • There is a difference in how one asks. See your asking "I have this valuable piece, and i would like to have a solution with this specification". That, is an order for work. While this is fine thats what you want. But people who answer want something too. There is nothing particularily interesting in providing you with said script. Theres nothing mentaly stimulating in it. And you dont particularily sound like youd be interested in learning (teaching you could be a challenge). So i suggest you leave the question a bit more open and ask how one could deal with this. – joojaa Jan 3 at 20:24
2

I found something that works.

var folder = Folder.selectDialog(); 
var doc = app.activeDocument;

var makerspace = app.activeDocument.layers.getByName("Makerspace"); 
var maakt = app.activeDocument.layers.getByName("Maakt");
var denkt = app.activeDocument.layers.getByName("Denkt");
var zoekt = app.activeDocument.layers.getByName("Zoekt");
var print = app.activeDocument.layers.getByName("Print");

var targetLayerName;
var layerName = "Layer";
var fabriks = Array();
var layers = doc.layers;

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

    targetLayerName = new String(layers[i].name);

    if (targetLayerName == layerName) {
        fabriks.push(layers[i]);
    }

    layers[i].visible = false;
}

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

    ExportLayers("Denkt", denkt);
    ExportLayers("Maak", maakt);
    ExportLayers("Zoek", zoekt);
    ExportLayers("Print", print);
    ExportLayers("makerspace", makerspace);
}

function ExportLayers(name, layer) {

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

        fabriks[i].visible = true;
        layer.visible = true;

        var fname = name + "_" + "FABRIK_" + i; 
        var saveInFile = new File(fname); 

        var exportOptions = new ExportOptionsSVG();
        var type = ExportType.SVG;

        exportOptions.embedRasterImages = true;
        exportOptions.embedAllFonts = true;
        exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
        app.activeDocument.exportFile(saveInFile, type, exportOptions);

        var exportOptions = new ExportOptionsPNG24();

        exportOptions.colorCount = 200;
        exportOptions.transparency = true;
        app.activeDocument.exportFile(saveInFile, ExportType.PNG24, exportOptions);

        fabriks[i].visible = false;
        layer.visible = false;
    }
}
1
  • It is completely cool (and suggested) to mark your own answer as correct if it solves your issue. – Scott Jan 4 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.