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

Make a text box attribute non-printing in InDesign v20.1 using JavaScript

New Here ,
May 09, 2025 May 09, 2025

I had so much success with my 1st post (question) Thanks @rob day Next question. Have a text box at top of page that is the document version. For proofing to client, I need this to print so client can see what version they are looking at. But when printing the live print I need to make this texy box non-printing. Looking for a script that can make text box non-print.  I have tried this script:

 

document.textFrames.item("version").nonprinting = true;

 

I have the text box labeled using script label as “version” (with no quotes).

I am getting below error:

Error1.PNG

I also tried the below script:

 

var version = doc.textFrames.itemByName("version");

version.nonprinting = true;

 

Getting this error:

Error2.PNG

Again Thanks VERY MUCH for all help and comments!

 

TOPICS
Scripting
703
Translate
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 ,
May 09, 2025 May 09, 2025

Are you sure you really do have a text frame named "version"? Your second script does work for me, unless I'm using a non-existent name, in which case it returns the same "Object is invalid" error.

Translate
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 ,
May 12, 2025 May 12, 2025

I am no expert but I am about 95% sure Text box is labeled version.Capture.PNG

Translate
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 ,
May 12, 2025 May 12, 2025
quote

I am no expert but I am about 95% sure Text box is labeled version

By @WCMProduction

 

As @Robert at ID-Tasker has already mentioned, then you need to check the label property of your text frames. In your original post, I missed that you were using Script Label (sorry!), I thought that "version" was the name assigned in the Layers panel.

Translate
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
LEGEND ,
May 09, 2025 May 09, 2025

@WCMProduction

 

I'm not JS guy - but maybe you've more than one "version" object in your document?

 

Translate
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 ,
May 12, 2025 May 12, 2025

Thanks for input, but there are no other script labels in Doc.

Translate
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
LEGEND ,
May 12, 2025 May 12, 2025
quote

Thanks for input, but there are no other script labels in Doc.


By @WCMProduction

 

Then it would be best if you iterate through all TFs - or only for a particular layer - and check "label" property. 

 

Translate
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 ,
May 12, 2025 May 12, 2025

I don’t think you can avoid the loop. This doesn’t throw an error, but the returned textFrame object has no properties:

 

var ver = app.activeDocument.textFrames.item("version")
$.writeln(ver) //returns [object TextFrame] but with no properties

 

Screen Shot 3.png

 

 

 

Translate
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 ,
May 09, 2025 May 09, 2025

Hi @WCMProduction , As @Robert at ID-Tasker  suggests I thnk you will have to loop through the textFrames—.getElements() converts the Collection into an Array.

 

var ver = app.activeDocument.textFrames.everyItem().getElements();
for (var i = 0; i < ver.length; i++){
    ver[i].nonprinting = true;
};  

 

Translate
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
LEGEND ,
May 09, 2025 May 09, 2025

@rob day

 

But you're not checking for "version"?

 

Translate
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 ,
May 12, 2025 May 12, 2025

Hope this helps - run it again it switches it off and on 

var doc = app.activeDocument;
var frames = doc.textFrames.everyItem().getElements();

for (var i = 0; i < frames.length; i++) {
    if (frames[i].label === "version") {
        frames[i].nonprinting = !frames[i].nonprinting;
        alert("Text frame with script label 'version' is now set to " + (frames[i].nonprinting ? "non-printing." : "printing."));
        break;
    }
}

  

Translate
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
LEGEND ,
May 12, 2025 May 12, 2025

@WCMProduction

 

Overall, instead of switching this one property for each TextFrame with the label - move them ONCE to a layer - then it will be a single click on the Layers pallet...

 

Translate
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
LEGEND ,
May 12, 2025 May 12, 2025

@WCMProduction

 

As you're a Windows user - would you like to try full version of my tool for a few days?

 

You can sort & filter by any of the 1000+ object properties, or you can find TextFrames by their (partial) contents abd / or text properties - 400+.

 

Then, if you need to do more - you can export PDF/JPEG/ePUB/etc. file(s).

 

So, if your workflow requires turning on/off visibility of some objects / layers and then export PDF(s) - you can have it done with one click. 

 

Or you can process in bulk whole folder with subfolders - of course, you can filter files first as well 😉 

 

And if you don't need to export after creating / editing each document - you want to save time - you can edit them first and then export PDF(s) later in bulk - during a lunch break 😉  

 

Exporting to a designated folder included. 

 

Translate
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 ,
May 13, 2025 May 13, 2025
LATEST

Hi @WCMProduction ,

in your specific case I would avoid the Script Label panel.

Instead I would simply name the text frame "version". Either do this using the Layers panel or by scripting when the text frame is selected:

app.selection[0].name = "version";

Then your code will work as expected:

app.documents[0].textFrames.itemByName("version").nonprinting = true ;

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

Translate
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