• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

298

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

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

 

 

Votes

Translate

Translate
Community Expert , 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();
    }
}

 

Votes

Translate

Translate
Community Expert ,
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();
    }
}

 

 

 

Votes

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

Votes

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

 

 

Votes

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.

Votes

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
Community Expert ,
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

Votes

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

 

Votes

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
Community Expert ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

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

Votes

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!

Votes

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