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

Script | Selection on merged row makes indesign crash

Explorer ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Hi everyone,

 

I'm facing a new problem with a script I was working on, it is supposed to read every cells I selected and let me apply a cell and paragraph style. It works fine unless my first selection is a merge row and the second one a row without any merge.

 

so selecting this two rows with this code makes indesign crash:

var mySelection = app.selection[0];
alert(mySelection.contents);

 

here's an example of my selection that crashes:

Capture d’écran 2020-09-21 à 18.18.06.png

either it crashes, or it shows me once in a while that error:

Capture d’écran 2020-09-21 à 17.59.03.png

I made an indd file example right here: https://www.dropbox.com/s/vwgx01jjgdd2c4n/row-issue.indd?dl=0

 

Thanks everyone,

Nicolas

TOPICS
Scripting

Views

620

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 , Sep 22, 2020 Sep 22, 2020

Hi Nicolas,

voted for a fix and commented your bug report at UserVoice.

For now it is sufficient to do one report only.

 

Important:

The more developers will vote for fixing the problem the more attention will be drawn and hopefully the bug will get fixed some day.

 

Thanks,
Uwe Laubender

( ACP )

Votes

Translate

Translate
Community Expert ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Hi Nocalas,

interesting case!

 

I get the same error message even if I only run the following statement from the ESTK:

app.selection

 

Could be a bug with InDesign's ExtendScript perhaps.

Tested with InDesign 2020 version 15.1.2.226 on Windows 10.

 

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 ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Also happening in VS Code Extendscript Debugger, on Catalina running the latest ID. Definitely a bug with selecting merged rows. If you select the merged cell as well, it works fine. I'll play around more. 

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 ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Also the following selection throws the error:

 

ErrorInSelectionOfCells-1.PNG

 

try
{
app.selection ;
}catch(e)
{ 
	$.writeln( "ERROR: " + e.number +", "+e.message ) ;
	alert( "ERROR: " +"\r"+ e.number +", "+e.message ) ;
};

 

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 ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Hi Brian,

also tested a bit:

Already an issue with InDesign CS6 version 8.1.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
Community Expert ,
Sep 21, 2020 Sep 21, 2020

Copy link to clipboard

Copied

Even if I do a selection of the three cells by scripting the resulting selection throws an error.

// Text frame with table is selected:
var table = app.selection[0].tables[0] ;

// Let's do a selection of three cells:
app.select( table.columns[0].cells[1] );
// No error:
app.select( table.columns[1].cells[2] , SelectionOptions.ADD_TO );
// No error:
app.select( table.columns[1].cells[1] , SelectionOptions.ADD_TO );

// THROWS ERROR:
try
{
app.selection ;
}catch(e)
{ 
	$.writeln( "ERROR: " + e.number +", "+e.message ) ;
	alert( "ERROR: " +"\r"+ e.number +", "+e.message ) ;
};

 

ErrorInSelectionOfCells-2.PNG

 

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
Explorer ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

Good morning everyone,

 

I ran other tests but it's still crashing.

There's no reference of error number "1" on google.

I'll continue to investigate and will keep you posted if I find a solution…

 

Thanks Uwe & Brian!

Nicolas

 

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 ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

Hi Nicolas,

strange enough maybe for you: In all my tests with your table and that selection I never had a crash.

Just error number 1 was thrown with the very simple message "selection".

 

Hm. I could do a bug report on InDesign UserVoice and also discuss that at prerelease…

 

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
Explorer ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

Hey Uwe,

 

Indesign kept crashing because I wasn't using try {} catch (e) {}. At least I'm able to stop the script before it crashes.

I opened a thread earlier this morning on uservoice: https://indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/41451565-script-selecti... but not on the prerelease yet.

 

Would that problem have better chances to be solved if you open a thread on usevoice and prerelease?

 

Thanks again,
Nicolas

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 ,
Sep 22, 2020 Sep 22, 2020

Copy link to clipboard

Copied

Hi Nicolas,

voted for a fix and commented your bug report at UserVoice.

For now it is sufficient to do one report only.

 

Important:

The more developers will vote for fixing the problem the more attention will be drawn and hopefully the bug will get fixed some day.

 

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

Copy link to clipboard

Copied

i had the same problem today.

Also, with this selection, InDesign crash if you select the "Edit" menu.

I found a workaround:

 

If you have a reference of the table, you can use "getTableSelectedCells(tbl);": return Array of cells

In scripts used by other users, if you do not have the table reference, use "getDocumentSelectedCells(doc);": return Array of cells.

 

function getDocumentSelectedCells (doc) {
    var fixNeeded = false;

    try {
        doc.selection;
    } catch (e) {
        fixNeeded = true;
    }

    if (fixNeeded) {
        var tbl = getTable(doc);
        return getTableSelectedCells (tbl);
    } else {
        var s = doc.selection;
        if (s.length === 1) {
            s = s[0];
    
            if ('cells' in s) {
                return s.cells.everyItem().getElements();
            } else {
                return [];
            }
         }
    }
}

function getTableSelectedCells (tbl) {
    var doc = tbl.storyOffset.parent.parent.getElements()[0];
    var fixNeeded = false;

    try {
        doc.selection;
    } catch (e) {
        fixNeeded = true;
    }

    if (fixNeeded) {
        var currentDoc = app.activeDocument.getElements()[0];
        app.activeDocument = doc;//doc containing the table must be the active document
        var maToGfx = app.menuActions.itemByName('$ID/Convert To Graphic Cell');
        var selectedCellsName = [];
        var selectedCells = [];

        var changed = app.doScript('toTxtCell(tbl)', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT);
        var maToGfx = app.menuActions.itemByName('$ID/Convert To Graphic Cell');

        //invoke menu action Table -> convert cell to graphic cell (target is the selection)
        maToGfx.invoke();

        var cells = tbl.cells;
        var i, ilen = cells.length;
        var gfx = CellTypeEnum.GRAPHIC_TYPE_CELL;

        for (i = 0; i < ilen; i++) {
            cell = cells[i];
            if (cell.cellType === gfx) {
                selectedCellsName.push(cell.name);//push(cell) doesn't work because references are lost after undo
            }
        }
    
        doc.undo();//undo maToGfx.invoke();

        if (changed > 0) {
            doc.undo();//undo toTxtCell function
        }

        //get cell references from cell names
        for (i = 0, ilen = selectedCellsName.length; i < ilen; i++) {
            selectedCells.push(cells.itemByName(selectedCellsName[i]));
        }

        app.activeDocument = currentDoc;//restore original activeDocument
        return selectedCells;
    } else {
        //fix not needed
        var s = doc.selection;
        if (s.length === 1) {
            s = s[0];
    
            if ('cells' in s) {
                return s.cells.everyItem().getElements();
            } else {
                return [];
            }
         }
    }
}

function toTxtCell (tbl) {
    var cells = tbl.cells;
    var i, ilen = cells.length;
    var cell;
    var gfx = CellTypeEnum.GRAPHIC_TYPE_CELL;
    var txt = CellTypeEnum.TEXT_TYPE_CELL;
    var changed = 0;

    //change graphic cells to text cells
    for (i = 0; i < ilen; i++) {
        cell = cells[i];
        if (cell.cellType === gfx) {
            cell.convertCellType(txt);
            changed++;
        } else if (cell.contents !== '') {
            cell.contents = '';//cells must be empty for the subsequent change to graphic cell
            changed++;
        }
    }

    return changed;
}

function getTable (doc) {
    var currentDoc = app.activeDocument;
    app.activeDocument = doc;

    var hop = Object.prototype.hasOwnProperty;
    var tblStr = app.translateKeyString('$ID/Table');
    var remStr = app.translateKeyString('$ID/Remove');

    var Mm = app.menus.itemByName('$ID/Main');//InDesign (main menu)
    var tblSm = Mm.submenus.itemByName(tblStr);//InDesign -> Table (submenu)
    var remSm = tblSm.submenus.itemByName(remStr);//InDesign -> Table -> Remove (submenu)
    var remTblMi = remSm.menuItems.itemByName(tblStr);//InDesign -> Table -> Remove table (menuItem)
    var remTblMa = remTblMi.associatedMenuAction;////InDesign -> Table -> Remove table (menuAction)

    var tableKeys = {};

    remTblMa.invoke();//remove table

    var tables = doc.stories.everyItem().tables.everyItem().getElements();
    var i, ilen = tables.length;
    var tbl;
    
    for (i = 0; i < ilen; i++) {
        tableKeys[tables[i].id] = true;
    }

    doc.undo();// undo remove table;

    tables = doc.stories.everyItem().tables.everyItem().getElements();

    for (i = 0, ilen = tables.length; i < ilen; i++) {
        if (!hop.call(tableKeys, tables[i].id)) {
            tbl = tables[i].getElements()[0];
            break;
        }
    }

    app.activeDocument = currentDoc;
    return tbl;
}

Roberto Bertazzoni (Italy)

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

Copy link to clipboard

Copied

Roberto said: "Also, with this selection, InDesign crash if you select the "Edit" menu."

 

Hi Roberto,

did you mean that InDesign crashed when you selected the Edit main menu in the user interface?

What exact version of InDesign did you test? On what operating system?

 

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

Copy link to clipboard

Copied

Hi Uwe,

 

InDesign CC2021 16.2.1 on MacOs Catalina 10.15.7

 

"did you mean that InDesign crashed when you selected the Edit main menu in the user interface?"

yes, with this type of selection.

 

Bye, Roberto

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

Copy link to clipboard

Copied

Hi Roberto,

well, I can replicate the bug with InDesign 2021 version 16.2.1 and yes, InDesign freezes when I tried to access the Edit menu with my mouse. I had to kill the application in my Task Manager for working on with my Windows 10 machine. No chance to switch to the open browser until I killed the InDesign application.

 

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

Copy link to clipboard

Copied

LATEST

Well, I provoked the crash again. Before I prepared a bug report that I sent with the crash report also pointing to this discussion here. My test files can be downloaded from my Dropbox account:

https://www.dropbox.com/s/kafrbfebdf4765a/210622-1-AccessMenuEditWillCrashInDesign-3TableCellsSelect...

 

A screenshot that illustrates the issue from my German InDesign 2021 version 16.2.1 on Windows 10:

 

ErrorInSelectionOfCells-2.PNG

 

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