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

Get Chapter Number variable content via script and convert it to binary

New Here ,
Nov 20, 2024 Nov 20, 2024

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.

TOPICS
How to , Scripting

Views

108

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 , Nov 20, 2024 Nov 20, 2024

chapter number content is a property of the document:

 

myChapterNumber = app.activeDocument.chapterNumberPreferences.chapterNumber;

Votes

Translate

Translate
Community Expert ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

chapter number content is a property of the document:

 

myChapterNumber = app.activeDocument.chapterNumberPreferences.chapterNumber;

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
New Here ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

LATEST

That's exactly what I needed, it's working perfectly now! Thank you so much, @Peter Kahrel, you're the best! 

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