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

Script no longer works in InDesign 2020

Community Beginner ,
Feb 16, 2020 Feb 16, 2020

Copy link to clipboard

Copied

Hi all

 

I have a script that has been working for me in Indesign 2018 and 2019. However having upgraded to 2020 it no longer works.

The script is meant to just delete empty graphic frames within tables. In 2018 and 2019 it does just this. In 2020 it deletes all of the graphic frames!

 

Any ideas why it would be doing this in 2020 but not in the previous versions? The script is as follows:

 

function inCell (frame) {
var p = frame.parent;
while (!(p instanceof Document || p instanceof Cell)) {
p = p.parent;
}
return p instanceof Cell;
}

r = app.documents[0].allPageItems;
for (i = r.length-1; i >= 0; i--) {
if (r[i].hasOwnProperty('graphics') && inCell (r[i]) && r[i].graphics.length == 0) {
r[i].remove();
}
}

TOPICS
Scripting

Views

1.4K

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 1 Correct answer

Community Expert , Feb 16, 2020 Feb 16, 2020

Hi Mike,

 

Change the if condition to the following

    if (r[i].constructor.name != "Image" && r[i].constructor.name != "PDF" && r[i].hasOwnProperty('graphics') && inCell(r[i]) && r[i].graphics.length == 0) {

 

The problem is that in versions prior to CC2020 the hasOwnProperty returns false for an image object, while for CC2020 it returns false. So we are adding to avoid the code to run if the item under processing is image or pdf

 

-Manan 

Votes

Translate

Translate
Community Expert ,
Feb 16, 2020 Feb 16, 2020

Copy link to clipboard

Copied

Hi Mike,

 

Change the if condition to the following

    if (r[i].constructor.name != "Image" && r[i].constructor.name != "PDF" && r[i].hasOwnProperty('graphics') && inCell(r[i]) && r[i].graphics.length == 0) {

 

The problem is that in versions prior to CC2020 the hasOwnProperty returns false for an image object, while for CC2020 it returns false. So we are adding to avoid the code to run if the item under processing is image or pdf

 

-Manan 

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 Beginner ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Awesome. That works.

 

Thanks Manan!!! Much appreciated

 

Cheers

 

Mike

 

For anyone that's interested that makes the full new script the following:

 

function inCell (frame) {
var p = frame.parent;
while (!(p instanceof Document || p instanceof Cell)) {
p = p.parent;
}
return p instanceof Cell;
}

r = app.documents[0].allPageItems;
for (i = r.length-1; i >= 0; i--) {
if (r[i].constructor.name != "Image" && r[i].constructor.name != "PDF" && r[i].hasOwnProperty('graphics') && inCell(r[i]) && r[i].graphics.length == 0)
{
r[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 ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Manan said:

The problem is that in versions prior to CC2020 the hasOwnProperty returns false for an image object, while for CC2020 it returns false. So we are adding to avoid the code to run if the item under processing is image or pdf

 

Hi Manan,

thank you very much for this observation:

hasOwnProperty("graphics") returns false on a placed Image object with InDesign CC 2019 and below.

 

And this has changed with InDesign 2020. So now:

hasOwnProperty("graphics") returns true on a placed Image object.

 

Could this be a bug fix perhaps? A new feature?

I wonder why property graphics was added.

 

FWIW: Object Image comes with property allGraphics in 2020 and below.

Maybe someone discovered that it would be only logical to add property graphics as well?

 

Regards,
Uwe Laubender

( ACP )

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 ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Hi Mike,

are you looking for graphic cells only?

Would you regard a frame empty with this simple test:

 

 

cell.cellType == CellTypeEnum.GRAPHIC_TYPE_CELL
&&
cell.pageItems[0].pageItems.length == 0

 

 

Regards,
Uwe Laubender

( ACP )

 

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
New Here ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Hi. So I plugged this in and it works beautifully to delete ALL graphic frames in a table but can it be modified to only delete empty graphic frames in the table?

 

Stumped,

Moz

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 Beginner ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Hi Moz. The following script is the one I'm currently using to delete empty graphic frames within all tables:

Hope it works for you! I'm using it on InDesign 2020. Cheers, Mike

 

function inCell (frame) {
var p = frame.parent;
while (!(p instanceof Document || p instanceof Cell)) {
p = p.parent;
}
return p instanceof Cell;
}

r = app.documents[0].allPageItems;
for (i = r.length-1; i >= 0; i--) {
if (r[i].constructor.name != "Image" && r[i].constructor.name != "PDF" && r[i].hasOwnProperty('graphics') && inCell(r[i]) && r[i].graphics.length == 0)
{
r[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
New Here ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

Thank you for responding.

hmmm. I am also using Indesign 2020 (15.1.3) but for me it deletes ALL image boxes in my table, even those with images in them. Could it be because the images I have placed are Illustrator .eps files???

 

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 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

Hi @mariah6627343,

Try changing the if statement to the following and then give it a try

if (r[i].constructor.name != "Image" && r[i].constructor.name != "PDF" && r[i].constructor.name != "EPS" && r[i].hasOwnProperty('graphics') && inCell(r[i]) && r[i].graphics.length == 0)

-Manan

 

 

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
New Here ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

Genious! That works. Thank you so much.

I had tried "eps" with no luck, I guess you really need to know the nuances of Java!!

 

But now I realize I need it to go a step farther to delete the empty table rows!! Any help there?

 

Clueless here.

Moz

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 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

With a table selected run the following code, it will remove the empty rows.

var rows = app.selection[0].rows
for(var i = rows.length - 1; i >= 0; i--)
	if(rows[i].cells.everyItem().contents.join(',').replace(/,/g, function(a){return ""}) == "")
		rows[i].remove()

-Manan

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
New Here ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

LATEST

Again, genious! Thank you so much for your help, works beautifully.

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