Show/Hide certain elements on page, when certain text is visible in specified area

Community Beginner ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

I have another query, if anyone can help me? 🙂

 

Is there any way in inDesign to show/hide certain specified elements on the page, if a certain word in another element is present?

TOPICS
How to , Import and export , Scripting , Type

Views

157

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

correct answers 1 Correct answer

Community Expert , Aug 17, 2022 Aug 17, 2022

@KuriousKatie asked: "Will this work if I add more things to that group, as in the grey box and the description below?"

 

Hi @KuriousKatie ,

you did another thread where you asked a similar question:

 

Show/Hide a group of items based on whether a word from a data merge is present in that group.
KuriousKatie, Aug 16, 2022

https://community.adobe.com/t5/indesign-discussions/show-hide-a-group-of-items-based-on-whether-a-word-from-a-data-merge-is-present-in-that-group/td-p/13138760

 

From your poste

...

Likes

Translate

Translate
Community Expert ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

You can make bodies of text "conditional," but what you describe doesn't seem to fit that. Even if you could make (the) InDesign (editing space) actively hide/display certain elements based on the presence or absence of a particular word, it would only be of workflow benefit, and not necessarily active in the deliverable end product. For that, in PDF, you could use Acrobat Javascript to show/hide "fields" based on the value of another given field.

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 Expert ,
Aug 10, 2022 Aug 10, 2022

Copy link to clipboard

Copied

Need some more specifics, but this rudimentary function would find a phrase in all top-level text frames on the doc's first page, and, if found, toggle off a specific top-level page item on the page. Note if you have grouped/anchored objects to toggle, this doesn't work. 

 

var page = app.activeDocument.pages[0];
var tfs = page.textFrames.everyItem().contents.join(" ");
if (/lorem ipsum/g.test(tfs)) {
    page.pageItems.itemByName("someframe").visible = false;
}

 

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 ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Basically, I have a file pulling data from a CSV, and I want to know if there is a way to show/hide the 'oestradiol' title circle and description text, if the text within the coloured circle is "noprostate". The text within the coloured circle used a grep style that displays red/green based on whether the field says 'safe' or 'unsafe'.

 

I've attached a mock file of what I mean, if someone can look over it to help me out?

 

Hopefully what I'm explaining I need makes sense?

 

Screenshot 2022-08-16 at 19.12.58.png

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 Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Assuming the title and text circle are grouped, then you could do something like this, adapting my code from above:

 

var pis = app.activeDocument.allPageItems;
var n = pis.length;
while(n--) {
try {
if (/noprostate/g.test(tfs)) {
    pis[n].parent.visible = false;
} catch(e) {//not a text frame probably}
}
}

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 ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Hi Brian,

 

Thanks for your help on this! 🙂

Will this work if I add more things to that group, as in the grey box and the description below?

 

Also, assuming the key for this to work is to Create the Data Merged document first, and then to run that script, yes?

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

I changed the word "noprostate" to "none", and saved as a plain text .jsx file, put in my script panel, and ran it. This error has shown up - any idea why?

 

Screenshot 2022-08-17 at 09.19.17.png

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 Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Add a new line before } catch(e) and innsert a closing brace }

 

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Added that line as you mentioned, but now when I try to run the script, nothing happens 😞

var pis = app.activeDocument.allPageItems;
var n = pis.length;
while(n--) {
try {
if (/none/g.test(tfs)) {
    pis[n].parent.visible = false;
}
} catch(e) {//not a text frame probably}
}
}

 

Any ideas why it's not running?

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 Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Another bug from when I adapted the previous code. Try this: 

var pis = app.activeDocument.allPageItems;
var n = pis.length;
while(n--) {
try {
if (/none/g.test(pis[n].parentStory.contents)) {
    pis[n].parent.visible = false;
}
} catch(e) {//not a text frame probably}
}
}

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Thank you for adapting your code 🙂 I have copied/pasted into into a plain text document and saved as a .jsx file and put into the script folder.

 

However, still nothing seems to happen when I run the script? 

Am I doing something wrong?

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 Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Did you group the set of elements you want to make invisible? They weren't in your sample merge doc. 

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 Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

LATEST

Also the extra bracket that you added in the catch statement to it's own line. Or delete my comment "//not a text frame probably"

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 Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

@KuriousKatie asked: "Will this work if I add more things to that group, as in the grey box and the description below?"

 

Hi @KuriousKatie ,

you did another thread where you asked a similar question:

 

Show/Hide a group of items based on whether a word from a data merge is present in that group.
KuriousKatie, Aug 16, 2022

https://community.adobe.com/t5/indesign-discussions/show-hide-a-group-of-items-based-on-whether-a-wo...

 

From your posted csv file there I can see that the first entry of e.g. Oestradiol is simply none.

So Brian's first[*] script will not work on a merged document with that data. The problem is to find a sufficient algorithm that could react on e.g. a group with that entry set and turn the whole group to invisible.

 

Also related is this thread you started in Aug 01, 2022:

 

Conditional Formatting to shapes from CSV text
KuriousKatie, Aug 01, 2022
https://community.adobe.com/t5/indesign-discussions/conditional-formatting-to-shapes-from-csv-text/t...

 

Here the link to my post where I am presenting a solution based on the "Conditional Formatting" thread:

 

https://community.adobe.com/t5/indesign-discussions/show-hide-a-group-of-items-based-on-whether-a-wo...

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

[*] Edited. Did not see all the answers that were posted the last two hours.

Forum notification via mail failed.

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