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

Javascript error only on a specific computer

Contributor ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Greetings,

I have a coworker on a Mac using InDesign v19.4 and they are getting the error below when running a script, but other coworkwers on Macs are able to run the script with no problem. I'm on a PC running InDesign v19.5 and the script runs fine for me as well. Any help getting it running on the one Mac would be much appreciated 🙂

 

Error Number: 1285

Error String: A document must have at least one page.

Line: 249

Source: graphicTemplate.masterSpreads[0].pages.lastitem0.remove();

 

TestriteVisual_0-1721742519497.png

 

TOPICS
Scripting

Views

247

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 ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Hi @TestriteVisual ,

seems that this specific document has only one page in the first parent page.

Maybe that script was executed a second time on the same document.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Community Expert ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Hi @TestriteVisual , I don’t think the error is computer specific—the error would happen on a document setup with Facing pages unchecked. You have to check if the targeted master spread has more than 1 page:

 

if (app.activeDocument.masterSpreads[0].pages.length > 1) {
	app.activeDocument.masterSpreads[0].pages.lastItem().remove();
}else{
	alert("No pages removed")
}

 

 

Screen Shot 13.png

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
Contributor ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Hi @rob day The script generates new pages from scratch, and will run with no documents open. But this problem is only happening on the one Mac, and the person was able to run the script before without error. The script is read-only so I'm not sure what could have changed in InDesign or on the one Mac to start causing the error. Thanks for any more insight.

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
Community Expert ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

"… The script is read-only so I'm not sure what could have changed in InDesign or on the one Mac to start causing the error."

 

Hi @TestriteVisual ,

well, if the script is adding a new document and that script does NOT specify if the document has facing pages, the default of that specific installed InDesign will apply. And it could be that this has changed to non facing pages documents. So that the script will add documents with only one page per parent page in this special case…

 

Example where the parameter facing-pages is left out so all could happen. A facing-pages document or a non-facing pages document; dependent on what the user has defined as default:

app.documents.add();


Adding a document with facing-pages explicitely defined. This would always add a facing-pages document:

app.documents.add
(
	{
		documentPreferences :
			{
				facingPages : true
			}
	}
);

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Contributor ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

Ah ok thanks for the info, yes so the problem was linked to what the File->Document Presets-> [Default] page is set to for the Facing Pages. My Default is set to Facing Pages CHECKED, and the script runs, but if I UNCHECK the Facing Pages option, the script error happens. This is snippet of the script setting Facing pages to UNCHECKED, but seems to give that error. Is there a way I can revised what I have to work regardless of what the default Facing Pages setting is set to, checked/unchecked? Thanks for your help.

 

//Set Layout Margin to Zero
function main() {

    var doc = app.activeDocument,
        allPages = doc.masterSpreads.everyItem().pages.everyItem().getElements().concat(doc.pages.everyItem().getElements());

    for (var i = 0; i < allPages.length; i++) {
        allPages[i].marginPreferences.properties = {
            top: 0,
            left: 0,
            right: 0,
            bottom: 0
        };
    }

}


app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set All Pages Margins');



//Uncheck Facing Pages
graphicTemplate.documentPreferences.facingPages = false;

//Set Parent to 1 Page
graphicTemplate.masterSpreads[0].pages.lastItem().remove();

 

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
Community Expert ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

"… but if I UNCHECK the Facing Pages option, the script error happens."

Hi@TestriteVisual ,

basically yes. But the matter is more complicated. If you have a named document preset active where facing-pages is unchecked the same will happen. So, before trying to remove any page from the first parent page, just check the length of pages in the spread.

 

// If more than 1 page is in the first parent page:
if( graphicTemplate.masterSpreads[0].pages.length > 1 )
{
// Remove all pages of the first parent page but the first page:
graphicTemplate.masterSpreads[0].pages.itemByRange(1,-1).remove();
};

 

Here I use itemByRange().

Counting starts from 0 on.

So 1 means the first page and -1 is the last page.
The range to remove pages is from the second to the last page of the first parent page.

( In case InDesign would be able to define more than two pages per parent page in the future with method add().

Or you want to run the script on documents with more than two pages with the first parent page. )

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Community Expert ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

But this problem is only happening on the one Mac

 

When the masterspread only has 1 page, you can’t remove its last page from the UI—the Trash icon is grayed out:

 

Screen Shot 14.png

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
Contributor ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

I'm sorry I'm not a programmer, I just know how to cut and paste text where needed. Could you please let me know what exactly needs to be edited? Thanks

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
Community Expert ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

LATEST

Share the entire script

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