I'm successfully loading a JSON file into InDesign via basil.js.
var jsonString = b.loadString("data.json");
var jsonData;
function setup() {
jsonData = b.JSON.decode(jsonString);
for (var i = 0; i < jsonData.length; i++) {
var myText = jsonData[i].text;
b.text(myText, 100, 10 * i, 100, 20);
};
}
b.go();
The result looks as expected:
What I'd like to achieve is
- That the text frames automatically fit their height to the content,
smth. like
fit(FitOptions.FRAME_TO_CONTENT);
- That the textBoxes continue until the page bounds and then a new page is added.
Any hints are warmly appreciated. Cheers!
for your first problem
you can just use
myText.fit(FitOptions.FRAME_TO_CONTENT);
. You don't have to stick with Basil if something is not implemented there.This is a little trickier. If you extend the textframes their size will change. You will need another variable outside of your loop that tracks the
geometricBounds
of the last frame and adds the next frame at the beginning of them. When your last bounds exceed the pageHeight you will need to add a new page.This is something to get you started. It is untested code.
Another hint. As you can see I omitted the
b.
Basil evolved a lot but we did not yet release the version 2. You can grab the latest version from the develop branch over at GitHub. The docs for that are located here.Edit 1
In Basil 2 you should be able to load the JSON using
loadString
and then decode it using JSON.parseThe Basil text function returns a
textFrame
. So thefit
function should work. If you run into bugs we are happy to accept bug reports over at github.Edit 2
The
fit
was called on the string you loaded from the JSON not on the result of thetext()
function.