InDesign show/hide layers via javascript
I'm attempting to create a data-merge document with a placed Illustrator showing the 50 states on each page. The illustrator file will eventually contain hidden layers showing each state in a contrasting color.
During the data-merge step, I'll place a state abbreviation in a text box identifiable via a script label (stateName). I'm hoping to set the visibility of its corresponding layer in the placed illustrator file to true. (If stateName = "CA," the CA layer in the placed illustrator file will be changed to visible on that same page).
Then the script would progress to the next page and perform the same function. For testing purposes, my attempt at this point only contains layers for California and Minnesota. Eventually it will contain all 50 states.
Currently, InDesign is pulling the variable twice from the page I have open, and placing the map twice on the second page, so I have a lot of work to do...
doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
var _folder = Folder.selectDialog("Select a folder");
var _files = _folder.getFiles();
var myPages =doc.pages.length;
for(var i =0;i<_files.length;i++)
{
var stateLabel = "stateName",
myPage = app.properties.activeWindow && app.activeWindow.activePage,
myTextFrames = myPage.textFrames.everyItem().getElements().slice(0),
l = myTextFrames.length,
myVariable
while (l--) {
if (myTextFrames[l].label != stateLabel) continue;
myVariable = myTextFrames[l].contents;
break;
}
if(myVariable == "CA")
{
function FindOCG(stateDestinationMap) {
this.layers["CA"].visible = true;
};
}
else(myVariable == "MN")
{
function FindOCG(stateDestinationMap) {
this.layers["MN"].visible = true;
};
}
}