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

Script - New Document

New Here ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Could you give me an advice please?

 

Is there a Script that would do - create a new document with a specific size, default name?

For example - Create a new file with dimensions 210x297mm.

 

Thank you.

TOPICS
Scripting

Views

114

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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Hi,

 

You can call app.documents.add() - documentation here - https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Documents.html

one of the params can be a document preset that allows you to set what you want - https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DocumentPreset.html#d1e316149

 

Using these together you should be able to do something like

// you might want to pick a specific one, or create it from scratch
var newPrefs = app.documentPresets.anyItem();

newPrefs.pageHeight = "297";
newPrefs.pageWidth = "210";

app.documents.add ( true, newPrefs);

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 ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

Hi @grafika75532081 , Also, in case you don’t know the preset name, or it might not exist, try this. It makes a temporary preset with your 210mm x 297mm dimensions—sets facing pages to true, and  margins to 25mm. You can check the API for other properties:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DocumentPreset.html

 

 

 

var dn = "My New Document";
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;

//A temporary preset with a unique name
var currdate = new Date
var ct =  "Temp-" + currdate.getTime();
var dp = makeDocPreset(ct);
dp.properties = {facingPages:false, pageHeight:297, pageWidth:210, pageOrientation:PageOrientation.PORTRAIT, top:25, bottom:25, left:25, right:25}

//make the new doc
var doc = app.documents.add(true, dp);
doc.name = dn
doc.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.MILLIMETERS, verticalMeasurementUnits:MeasurementUnits.MILLIMETERS}

//remove the temp preset
dp.remove();

/**
* Makes a new document preset 
* @ param preset name name 
* @ return the new preset 
*/
function makeDocPreset(n){
    if (app.documentPresets.itemByName(n).isValid) {
        return app.documentPresets.itemByName(n);
    } else {
        return app.documentPresets.add({name:n});
    }
}

 

 

 

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
People's Champ ,
Oct 19, 2022 Oct 19, 2022

Copy link to clipboard

Copied

LATEST

What's the need precisely? Is the create document routine part of a bigger script? 

Because document presets would do the same without even coding. 

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