2

I am working on a CEP plugin for InDesign. Since the jsx doesn't support much functions (ES3) I want to export objects from InDesign to javascript and then continue working on them there. To be able to do this I have to send JSON from the plugin, but stringifying does not work

Here is an example of a jsx-file that should return an array of graphic lines

#include './json2.jsx';

var objMain = {};
objMain.getLines = function () {
    var returnObject = [];
    // Loop through all graphic lines
    for (var i = 0; i < app.activeDocument.graphicLines.length; i++) {
        returnObject.push(app.activeDocument.graphicLines[i]);
    }

    return JSON.stringify(returnObject);
}

objMain.getLines();

But when I run it I get this from json2:

throw new TypeError("Converting circular structure to JSON");

I've tried iterating the object to create a new object that just contains the nested object without functions and circular dependencies, but I get "the property is not applicable in the current state" if I try to check with "typeof". I've tried many kinds of ES3-flatten methods without luck

Anyone know how to get an (entire) object JSON'ified through jsx/CEP?

I tried looping through objects removing circular dependencies, but the lack of functions in CEP/ES3 doesn't allow much

Taztevenn
  • 21
  • 1
  • 3

1 Answers1

0

The short answer that the InDesign object model is highly circular. To achieve what you want here, I'd recommend extracting whatever data you need from the graphicLine objects and storing them in your own JSON objects. Then write a function on the receiving end to create new graphicLines using that restored data.

I highly recommend this site for study of the InDesign object model:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

Greg Anderson
  • 540
  • 4
  • 14