Copy link to clipboard
Copied
Hello Everyone,
I'm working on this sci-fi book formatting project and I have this very specific request, where the client wants to display the chapter number followed by its representation in binary numbers, so it gives off hi-tech vibes. For example:
Chapter 19
1 0 0 1 1
Since it is a very unusual feature, and there is a large number of chapters, I wrote a dedicated script that converts the chapter number to its binary representation and creates a new text variable with this binary value, so I don't have to do it manually for every single one of them.
The algorithm for the convertion itself is working fine, however, I'm facing different issues. I couldn't get the content of the chapter number text variable via script. I tried something like:
var Value= app.activeDocument.textVariables.item("Chapter Number").variableOptions.contents;
but it returns me the error 55, " the object does not support the property or method 'contents' ".
If I try the same line of code, using a text variable created by me, it works fine and the script gets the variable content. So this error is avoiding me getting the chapter number itself.
Someone else told me that the chapter number variable content can't be obtained directly, since it depends on the document context to be generated. I was instructed to create a temporary text frame via script, insert the chapter number text variable on it, collect the text frame content and then delete that said text frame. However, my Indesign scripting skills are poor and I was not able to acheive the desired result.
How can I get the chapter number value via script? Is there a less convoluted and cumbersome way to get it without placing it in a temporary text frame? I thought it would be simple to achieve, but nothing seems to work.
Thanks in advance.
chapter number content is a property of the document:
myChapterNumber = app.activeDocument.chapterNumberPreferences.chapterNumber;
Copy link to clipboard
Copied
chapter number content is a property of the document:
myChapterNumber = app.activeDocument.chapterNumberPreferences.chapterNumber;
Copy link to clipboard
Copied
That's exactly what I needed, it's working perfectly now! Thank you so much, @Peter Kahrel, you're the best!