Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Text and Text Variable with logic

Community Beginner ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

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

TOPICS
How to, Scripting

Views

186

Likes

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
Adobe Community Professional ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

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.

Likes

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
Community Beginner ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

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

 

Likes

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
Community Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hi Peter,

a very BIG thanks for your suggestion: it's lucky when I can found someone that is so kind and clear.

 

About hide text I'm unfortunately right to think that Indesign does'n have "hidden text" as Word, and your solution is ok.

I think that also with conditional text I can do something: with script, if I can set "- ##" text as conditional text and I don't set condition for display conditional text, the text disappear and the space used is exactly 0. But I must try what I must do to reset conditional text before rerunning the script, or if I can write a script that manages all the case. I will study.

 

About script, another big thanks to you: clear, I undestand it.

I agree that the better way is a name for the header frames and I can name the frame in the master page (left and right).

 

Only a last question: where can I find documentation about Indesign scripts (and some examples)?

I have found documentation for CS6, but nothing for Indesign CC: must I do better search or can I use "old" documentation?

 

Thank you again.

Likes

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
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

You're right, InDesign has conditional text, which is the equivalent of Word's hidden text. And you also right that in this case, conditional text is more appropriate because it's simpler.

 

But I must try what I must do to reset conditional text before rerunning the script, or if I can write a script that manages all the case.

 

I would simply have the script delete the condition, re-create it (it's simple), and run again.

 

As to documentation, most of the documentation for CS5 and later is useful. Scripting has changed in the sense that more APIs have become available (InDesign's object model has grown), but the scripting itself hasn't changed in principle.

 

The most recent guide is this one: https://sites.fastspring.com/publishingsecrets/product/JSID2

 

P.

Likes

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
Community Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hi Peter,

thanks for your link to documentation.

Only a little last question: suppose I define in Master page A a text box named i.e. ArtBox with the 2 variables, and I apply this Master page A to all pages of my document.

When I run the script searching all text boxes named ArtBox, can you confirm that there is a way to select only the ArtBox in the 3000+ pages (and not in the Master page A) and that I can apply character style by script to the content of ArtBox in each page separately (the box is normally unaccessible from user interface)?

Andrea Treggia

Likes

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
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

Yes, you have to override the ArtBox frame on to every document page, otherwise the varibles can't be instantiated. When you add pages to your document manually, simply Shift+Click the ArtBox item and it will be overridden on to the page. If you added that box on a master page of your existing 3,000+-page document, then you can use a script to override the ArtBox frame on all the pages.

 

P.

Likes

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