Deleteing "named" text frame?

Advocate ,
May 31, 2022 May 31, 2022

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

TOPICS
Scripting

Views

103

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , May 31, 2022 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();
    }
}

 

 

Likes

Translate

Translate
Adobe Community Professional , Jun 01, 2022 Jun 01, 2022

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

 

Likes

Translate

Translate
Adobe Community Professional ,
May 31, 2022 May 31, 2022

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

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 31, 2022 May 31, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2022 May 31, 2022

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

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 01, 2022 Jun 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

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:

 

Screen Shot 6.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

Ah, right, left the parentheses off of remove. Good catch, Rob. My bad. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 02, 2022 Jun 02, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines