Search code examples
javascriptadobe-indesign

Conditional layer visibility based on variable in data merge for InDesign


Is it possible to set a conditional formatting that would update visible layers based on a set value when using data merge? Basically you would have some sort of value set to the side, say 1, 2, or 3, and based on that value, it would set layer 1, 2, or 3 to be visible. Or something along those lines.

Either something like this or would it be possible to automatically delete a row or column in a table if it is empty? Similar to how the "Remove blank lines for empty fields" works.

If not possible within InDesign, is there a script that might work that could be added to my data merge script that would automatically delete empty rows or columns?

Any suggestions would be greatly appreciated!

Thank you!


Solution

  • The following script ended up working for what I needed:

    var doc = app.activeDocument;
    var lays = doc.layers;
    var tf = doc.textFrames.itemByName("LayerInfo");
    var c = tf.parentStory.contents;
    var i = lays.length;
    while (i--) {
        if (lays[i].name == "MARKET " + c || lays[i].name == "Layer 1") {
            lays[i].visible = true;
        } else {
            lays[i].remove();
        }
    }
    tf.remove();