Create on the existing file a rectangle with black fill.
The script must delete the path items with white fill and it must delete the text frames with no content.
Result after the script is only that rectangle with black fill.
The script described here below is for deleting stray points, empty textframes,... if that would be helpful for you.
#target illustrator
var idoc = app.activeDocument;
var straypoints = [];
for (i=0; i<idoc.pathItems.length; i++) {
var ipath = idoc.pathItems;
if (ipath.pathPoints.length==1)
straypoints.push(ipath);
}
for (j=0; j<idoc.textFrames.length; j++) {
var itext = idoc.textFrames;
if (itext.textRange.length==0)
straypoints.push(itext);
}
for (k=0; k<straypoints.length; k++)
straypoints.remove();
Jesse, I had a look at that file and your white path items are 0% of a gray color… Easy enough to get rid of… The text frames are NOT being deleted because they do have content NOT empty… There are either 1 or two invisible characters in each Im not sure how to deal with this just yet ( need to check how to get the character values )… Making a rectangle and filling it black is easy stuff… Here I made one half the size of the doc… Not filled it just yet do you need 100% gray color or 0,0,0,100 CMYK? From this you can see I reset/reuse variables… You only need i,j,k and so on when looping inside of loops… The lines that use $.writeln( someValue ); are how I write back to the console for debugging…
#target Illustrator
function tidyMyFile() {
if ( app.documents.length == 0 ) { return; }
var i, count, doc, rec, uil;
uil = app.userInteractionLevel;
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
doc = app.activeDocument;
count = doc.pathItems.length;
$.writeln( count );
for ( i = count-1; i >= 0; i-- ) {
if ( doc.pathItems.fillColor.gray == 0 ) { doc.pathItems.remove(); }
};
count = doc.textFrames.length;
$.writeln( count );
for ( i = count-1; i >= 0; i-- ) {
if ( doc.textFrames.contents == ' ' || doc.textFrames.contents == ' ' ) { doc.textFrames.remove(); }
};
rec = doc.pathItems.rectangle( 0, 0, doc.width/2, -doc.height/2 );
//rec.fillColor = ;
app.redraw();
app.userInteractionLevel = uil;
};
tidyMyFile();
Edit the contents were \s or \s\s