Copy link to clipboard
Copied
I am wanting to scan through all open documents and look for a dynamic textFrame variable called coverPageVolume
When the script finds the textFrame associated with this variable.... I would like it to remove the textFrame.
I can get it to change the contents...but any time I try to get it to remove the textFrame it locks my illustrator up.
What am I doing wrong here?
for (var i = 0; i < documents.length; i++) {
var currentActiveDoc = app.documents;
app.activeDocument = currentActiveDoc;
var theDocVariables = currentActiveDoc.variables
for (z = 0; z < theDocVariables.length; z++) {
if (theDocVariables
.name == "coverPageVolume") { theDocVariables
.pageItems[0].remove(); }
}
}
Aha, indeed this is what happens to me too. It looks like remove() on all of the items will lock it up like you say.
But, we can do this workaround to select all the items and then run a delete command:
#target illustrator
function test(){
var doc = app.activeDocument;
doc.selection = null;
for(var i=0; i<doc.variables.length; i++){
if(doc.variables.name == "Variable3"){
for(var j=0; j<doc.variables.pageItems.length; j++){
doc.variables.pageItems
};
}
};
...
Copy link to clipboard
Copied
Use another for loop:
for(var j=theDocVariables
theDocVariables
};
Copy link to clipboard
Copied
Thank you for the input Silly-V ! When I try to run that script it still locks up my illustrator. I believe the issue is I have to delete the variable before I can delete the textFrame? Because when I run the following script it works....it is just slow.
for (var i = 0; i < documents.length; i++) {
var currentActiveDoc = app.documents;
app.activeDocument = currentActiveDoc;
var theDocVariables = currentActiveDoc.variables
for (z = 0; z < theDocVariables.length; z++) {
if (theDocVariables
.name == "coverPageVolume") { // Make the textFrame blank
theDocVariables
.pageItems[0].contents = ""; // Delete the associated variable
theDocVariables
.remove(); }
}
var allText = currentActiveDoc.textFrames;
var straypoints = [];
// Check text frame length - Path Cleanup
for (j = 0; j < allText.length; j++) {
var itext = allText
; if (itext.textRange.length == 0)
straypoints.push(itext);
}
// Remove stray items - Path Cleanup
for (k = 0; k < straypoints.length; k++) {
straypoints
.remove(); //alert(straypoints.length + " stray points removed");
}
}
Any other methods you can think of that would allow me to delete the variable and textFrame?
Copy link to clipboard
Copied
Aha, indeed this is what happens to me too. It looks like remove() on all of the items will lock it up like you say.
But, we can do this workaround to select all the items and then run a delete command:
#target illustrator
function test(){
var doc = app.activeDocument;
doc.selection = null;
for(var i=0; i<doc.variables.length; i++){
if(doc.variables.name == "Variable3"){
for(var j=0; j<doc.variables.pageItems.length; j++){
doc.variables.pageItems
};
}
};
app.executeMenuCommand("clear");
};
test();
Copy link to clipboard
Copied
this is EXACTLY what I was trying to accomplish! Thank you Silly-V