Skip to main content
ATreggia
Participating Frequently
February 15, 2021
Question

Text and Text Variable with logic

  • February 15, 2021
  • 1 reply
  • 1217 views

Hi and thanks in advance for your help.

I have a big document in Indesign (3000+ page) about Italian civil code: the text is composed of the articles of the laws.

For example:

Art. 12 - Temporary job

... some paragraph text 

Art. 13 - Business trip

... some paragraph text

I must put an header on each page to tell to reader what articles are on the page: "Art. 12" if in the page there is only the text of article #12 or "Art. 12-14" if in the page are the articles #12 to #14. The numbers are with ad hoc character style (ArtNumber)

I can use 2 master pages with some Text Variables:

- the MasterA  for the first case: "Art." + FirstArt (Text Variable, style ArtNumber, running header, first on page)

- the MasterB for the second case: "Art." + FirstArt (Text Variable, style ArtNumber, running header, first on page) + " - " + LastArt (Text Variable, running header, style ArtNumber, last on page)

The BIG problem for 3000+ pages is: if I modify some text and on the page with only one article now there are 2 articles, I must change the master page and check 3000+ pages!

 

I'm searching for some "if statement" like: if FirstArt == LastArt then "Art." + FirstArt else "Art." + FirstArt + "-" + LastArt, but this solution can't be implemented.

 

How can I solve this situation and how can I write an header text in a text box that can change related to the quantity of articles in the corresponding page?

Thanks again.

Andrea Treggia - Italia

This topic has been closed for replies.

1 reply

Community Expert
February 16, 2021

Use a single master, not separate masters for different situations in the Art Number variables -- as you experienced, it will soon drive you mad.

Set the headers to include the variable for the first item on the page, a dash, and the variable for the last item on the page. Then use a script to check whther the first and the second variable are the same. Get all running header frames, then if in a frame the first and the last variable have the same vakue, apply a character style that hides the dash and the second variable. You compare two variables as follows:

if (frame.textVariableInstances.length === 2 
    && frame.textVariableInstances[0].resultText == frame.textVariableInstances[1].resultText) {
  // Hide the second instance
}

That hiding character style can apply simply the Paper colour.

When the text changes and reflows, simply delete the character style, recreate it, and run the script again.

P.

ATreggia
ATreggiaAuthor
Participating Frequently
February 17, 2021

Hi Peter,

thanks for you solution that is simple and clear.

Only a problem: as in the attached image, the strings "Art. ## [- ##]" are aligned to the left in the left page and to the right on the right page. When the two variables are equal and from the dash hidden by character style, on the left page all is ok but on the right page seems that the headers has a wrong alignement if compared with strings with two different article's number.
May be that I can use hidden text like Word, but I'm not sure that it exist. Any suggestion?

 

I have only a (may be big) problem: I never written a script for Indesign ... but at least I write code since ... too many year.

So I don't understand, may be because I'm Italian and I use basic english, what do you mean with "Get all running header frames": how can tell to the script that it must examine all header frames? A for/while cycle?

The truth is that I know how install scripts, but I must study scripting for Adobe: how can I applicate a style to a text? How ... 

Where can I find documentation about Indesign scripts (and some examples)?

 

Many many thanks.

Community Expert
February 17, 2021

Andrea -- To really hide some text, apart from giving it the Paper colour you can set the type size to 0.1 pts and the horizontal scale to 1%. That makes the text (or, in this case, the dash and the cintent of the text variable) practically invisible.

 

 what do you mean with "Get all running header frames": how can tell to the script that it must examine all header frames? A for/while cycle?

 

That depends on how your document was set up. Ideally, if you know about this problem before you start, you name the header frames on the Layers panel. That way they are easy to find.

 

Another way to go about it is to look for all text frames that have two character-style variables separated by a dash. The Grep search for this is \x{0018}-\x{0018}. It's probably safe to assume that this finds only your Art variables. (Note: \x{0018} finds any variable. The code for character-style variables is ~Z, but that finds just a single variable, not two variables separated by a dash. That's probably a bug.)

 

The script code would be something like this:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\x{0018}-\\x{0018}';
art = app.documents[0].findGrep();
for (i = 0; i < art.length; i++) {
  if (art[i].textVariableInstances[0].resultText == art[i].textVariableInstances[1].resultText) {
    // Apply the character style from the second to the last character of the found string.
    // JavaScript starts counting at 0, so character[1] is the second character in the found text.
    art[i].characters.itemByRange(1,-1).appliedCharacterStyle = app.documents[0].characterStyles.item('hide');
  }
}

 

Peter