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

Deleteing "named" text frame?

Advisor ,
May 31, 2022 May 31, 2022

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

 

 

Translate
Community Expert , Jun 01, 2022 Jun 01, 2022

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

 

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

 

 

 

Translate
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
Advisor ,
May 31, 2022 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"?

Translate
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

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

 

 

Translate
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
Advisor ,
Jun 01, 2022 Jun 01, 2022

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.

Translate
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

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

Translate
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

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

 

Translate
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

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

Translate
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
Advisor ,
Jun 02, 2022 Jun 02, 2022
LATEST

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

Translate
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