Skip to main content
Inspiring
June 25, 2023
Question

How to transfer list of list between js and jsx in Indesign panel?

  • June 25, 2023
  • 8 replies
  • 1034 views

How to transfer list of lists between js and jsx in Indesign panel?

 

JS side:

var listOfList = [

[1,2,3],

[2, "2", "hello"]

];

 

ata = JSON.stringify( listOfList )
var script = 'listTransfer( ' + ata + ');'

csInterface.evalScript(script);

 

 

JSX side:

#include "json_p.js"

function listTransfer(inpuList){

var listOfLists = JSON.parse(inpuList)
return listOfLists

}

 

 

And this above does not work.

The  real list of list I need to transfer is read from excel file (content of each cell is element in list which is part of a bigger list). 

Maybe I could try to export as csv from js and then import from jsx. 

But any suggestion how to improve this or some other approch?

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

Loic.Aigon
Legend
June 25, 2023
quoteAnd this above does not work.

By @livl17017666

 

Ok but what does this return:

 

csInterface.evalScript(script, function(message){
console.log(message);
});

 

What is it in your debugger?

 

Is your function even called? Easy to check:

JSX side:
alert("trying to load json_p");
#include "json_p.js"
alert("JSON is "+(typeof JSON));

function listTransfer(inpuList){
alert("I am called");
var listOfLists = JSON.parse(inpuList)
alert("listOfLists is of type:" + (typeof listOfLists));
return listOfLists

}

At the moment, you can already investigate to find the root of your problem.

Inspiring
June 27, 2023

Yes I did something similar on Sunday.

And what was sent to jsx was acctually array not string.

 

With this line of code from js:

ata = JSON.stringify( listOfList )

var script = "listTransfer(" + ata + ")";

csInterface.evalScript(script);


I expetcted that it will be the string.

 

 

 

Community Expert
June 27, 2023

So did it not work? Add in alert on both ends and see what you get. You would have to convert string to object on the jsx end as well.

-Manan

-Manan
rob day
Community Expert
Community Expert
June 25, 2023
var xlsf = File.openDialog("Please Choose an Excel file");

alert("Contents of row 2 cell 3: \r" + getExcelArray(xlsf)[1][2]);

/**
* Converts an Excel table into a nested array 
* @ param the Excel file path 
* @ return a nested array for the table 
*/

function getExcelArray(xf){
    var doc = app.activeDocument;	
    var temp = doc.pages[0].textFrames.add ({geometricBounds: ["0pts","0pts","1000pts","1000pts"], textFramePreferences: {ignoreWrap: true,}});
    try {
        temp.place(xf);
        var xta = temp.parentStory.tables[0].rows.everyItem().contents; 
    }catch(e) {
        temp.remove()
        alert(e)
    }  
    temp.remove();
    return xta;
}
rob day
Community Expert
Community Expert
June 25, 2023

Hi @livl17017666 , This thread might help—script to convert an .xls table into a nested array. See @Peter Kahrel ’s simplified code at the end:

 

https://community.adobe.com/t5/indesign-discussions/how-to-use-xlsx-extendscript-js/m-p/13782669#M52...