Skip to main content
Inspiring
May 31, 2022
Answered

Deleteing "named" text frame?

  • May 31, 2022
  • 2 replies
  • 873 views

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

This topic has been closed for replies.
Correct answer rob day

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.


Think there’s a typo in @brian_p_dts ’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();
    }
}

 

2 replies

cbishop01Author
Inspiring
June 2, 2022

This community is so awesome! Thank you all so much!

brian_p_dts
Community Expert
Community Expert
May 31, 2022

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();
    }
}

 

 

 

cbishop01Author
Inspiring
May 31, 2022

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"?

brian_p_dts
Community Expert
Community Expert
May 31, 2022

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();
    }
}