Copy link to clipboard
Copied
Hello all,
I am wanting to delete a text frame called "Back" is there a script out there that already does something like this? I've seen scripts that delete "ALL FRAMES" or all text in frames but i cannot get any to specifically work for my text frame.
Thanks
Chris
Sure, just take out the second clause of the if statement from above. This would delete any page item (text frame, rectangle, oval, line, etc.) named "Back". Edit: added () to .remove()
var apis = app.activeDocument.allPageItems;
for (var i = apis.length - 1; i >= 0; i--) {
if (apis[i].name == "Back") {
apis[i].remove();
}
}
Think there’s a typo in @brianp311 ’s code. Should be .remove():
var apis = app.activeDocument.allPageItems;
for (var i = apis.length - 1; i >= 0; i--) {
if (apis[i].name == "Back") {
apis[i].remove();
}
}
Copy link to clipboard
Copied
Safest way would be to use all page items. Edit sorry change Black to Back, and also this will delete all text frames with that name, fyi. Edit 2: Fixed typo in .remove() call
var apis = app.activeDocument.allPageItems;
for (var i = apis.length - 1; i >= 0; i--) {
if (apis[i].name == "Black" && apis[i] instanceof TextFrame) {
apis[i].remove();
}
}
Copy link to clipboard
Copied
will this also delete image frames as well? some of the "Backs" have pictures in them as well that i'd like to be deleted. This may actually be my entire issue for my test file not deleting the text frame. it was a text frame until a image was placed into it. So is there a way to make it delete any frame (Text or image) with the name "Back"?
Copy link to clipboard
Copied
Sure, just take out the second clause of the if statement from above. This would delete any page item (text frame, rectangle, oval, line, etc.) named "Back". Edit: added () to .remove()
var apis = app.activeDocument.allPageItems;
for (var i = apis.length - 1; i >= 0; i--) {
if (apis[i].name == "Back") {
apis[i].remove();
}
}
Copy link to clipboard
Copied
This isnt working for me. when i add this to my Eventlistener or keep it as a standalone script it doesnt delete anything that i change the "Back" name to. I tried it on my text frame called "Back" and then Edited the Back to "OUR Barcode" to see if it would delete that.
Copy link to clipboard
Copied
Hi Chris, Can you select one of the frames named "Back" and post a screen capture of your Layers panel so we can see the name? Something like this:
Copy link to clipboard
Copied
Think there’s a typo in @brianp311 ’s code. Should be .remove():
var apis = app.activeDocument.allPageItems;
for (var i = apis.length - 1; i >= 0; i--) {
if (apis[i].name == "Back") {
apis[i].remove();
}
}
Copy link to clipboard
Copied
Ah, right, left the parentheses off of remove. Good catch, Rob. My bad.
Copy link to clipboard
Copied
This community is so awesome! Thank you all so much!