I'm working on a script to clean up a doc after a data merge. Essentially it'll set the visibility of a given item based on a text field value. Example below:
var QEBlue = app.activeDocument.pageItems.itemByName('QE 287');
var QEGreen = app.activeDocument.pageItems.itemByName('QE 347');
etc......
if (Panto.contents==('QE BLUE')){
QEBlue.visible = true;
QEGreen.visible = false;
QEBurg.visible = false;
QERed.visible = false;
QEBrown.visible = false;
QES57.visible = false;
QEReflex.visible = false;
QEBuff.visible = false;
}
else if (Panto.contents==('QE GREEN')){
QEBlue.visible = false;
QEGreen.visible = true;
QEBurg.visible = false;
QERed.visible = false;
QEBrown.visible = false;
QES57.visible = false;
QEReflex.visible = false;
QEBuff.visible = false;
Right now this works however I do end up with a lot of extra objects that could frankly get removed.
Option A was changing the script to run like:
if (Panto.contents==('QE BLUE')){
QEBlue.visible = true;
QEGreen.remove();
etc.....
But this doesn't really save a lot of time in writing the script, plus it creates a lot of steps for it to run through.
Option B would be something along the lines of:
if (app.activeDocument.pageItems.everyItem().visible = false){
app.activeDocument.pageItems.everyItem().remove();
}
But instead of removing everything it just hides everything.
In an ideal world, the script would read
if (Panto.contents==('QE BLUE')){
QEBlue.visible = true;
"everything else".remove();
Right now the doc has 3 layers and each layer has corresponding items, so just hiding & deleting layers isn't really a solution.
So in the end I've got a document with only the visible elements. If there's a way to write this efficiently it would be greatly appreciated, otherwise, I can brute force it by telling the script to change every item one by one.