Skip to main content
Participant
January 27, 2022
Answered

Page Size / Diagonal

  • January 27, 2022
  • 2 replies
  • 152 views

Help me 🙂

I need a sctipt for InDesign to show/count the diagonal of the active document.

I designed elements using https://scriptui.joonas.mebut I need help to code functions etc.

THX EVERYONE 🙂

{"activeId":47,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"text":"Name","preferredSize":[0,0],"margins":16,"orientation":"row","spacing":10,"alignChildren":["left","top"],"varName":"","windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"enabled":true}},"item-1":{"id":1,"type":"Panel","parentId":20,"style":{"text":"Title","preferredSize":[0,0],"margins":10,"orientation":"column","spacing":10,"alignChildren":["center","top"],"alignment":null,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"enabled":true}},"item-3":{"id":3,"type":"EditText","parentId":6,"style":{"text":"","preferredSize":[60,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-4":{"id":4,"type":"StaticText","parentId":6,"style":{"text":"Height","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-5":{"id":5,"type":"EditText","parentId":6,"style":{"text":"","preferredSize":[60,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-6":{"id":6,"type":"Group","parentId":1,"style":{"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["left","center"],"alignment":null,"varName":null,"enabled":true}},"item-20":{"id":20,"type":"Group","parentId":0,"style":{"preferredSize":[0,0],"margins":0,"orientation":"column","spacing":10,"alignChildren":["fill","top"],"alignment":null,"varName":"","enabled":true}},"item-36":{"id":36,"type":"Group","parentId":1,"style":{"preferredSize":[0,0],"margins":[0,0,0,0],"orientation":"row","spacing":10,"alignChildren":["center","center"],"alignment":null,"varName":null,"enabled":true}},"item-38":{"id":38,"type":"Button","parentId":36,"style":{"text":"Close","justify":"center","preferredSize":[0,0],"alignment":null,"varName":"cancel","helpTip":null,"enabled":true}},"item-39":{"id":39,"type":"StaticText","parentId":6,"style":{"text":"Width","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-42":{"id":42,"type":"Group","parentId":1,"style":{"preferredSize":[140,0],"margins":0,"orientation":"row","spacing":8,"alignChildren":["right","center"],"alignment":null,"varName":null,"enabled":true}},"item-46":{"id":46,"type":"EditText","parentId":42,"style":{"text":"","preferredSize":[60,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-47":{"id":47,"type":"StaticText","parentId":42,"style":{"text":"Diagonal of the page","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}}},"order":[0,20,1,6,39,3,4,5,42,47,46,36,38],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"functionWrapper":false,"compactCode":false,"showDialog":true,"afterEffectsDockable":false,"itemReferenceList":"None"}}
*/ 

// DIALOG
// ======
var dialog = new Window("dialog"); 
    dialog.text = "Name"; 
    dialog.orientation = "row"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.orientation = "column"; 
    group1.alignChildren = ["fill","top"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

// PANEL1
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"}); 
    panel1.text = "Title"; 
    panel1.orientation = "column"; 
    panel1.alignChildren = ["center","top"]; 
    panel1.spacing = 10; 
    panel1.margins = 10; 

// GROUP2
// ======
var group2 = panel1.add("group", undefined, {name: "group2"}); 
    group2.orientation = "row"; 
    group2.alignChildren = ["left","center"]; 
    group2.spacing = 10; 
    group2.margins = 0; 

var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Width"; 

var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.preferredSize.width = 60; 

var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "Height"; 

var edittext2 = group2.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.preferredSize.width = 60; 

// GROUP3
// ======
var group3 = panel1.add("group", undefined, {name: "group3"}); 
    group3.preferredSize.width = 140; 
    group3.orientation = "row"; 
    group3.alignChildren = ["right","center"]; 
    group3.spacing = 8; 
    group3.margins = 0; 

var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "Diagonal of the page"; 

var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}'); 
    edittext3.preferredSize.width = 60; 

// GROUP4
// ======
var group4 = panel1.add("group", undefined, {name: "group4"}); 
    group4.orientation = "row"; 
    group4.alignChildren = ["center","center"]; 
    group4.spacing = 10; 
    group4.margins = [0,0,0,0]; 

var cancel = group4.add("button", undefined, undefined, {name: "cancel"}); 
    cancel.text = "Close"; 

dialog.show();

 

This topic has been closed for replies.
Correct answer rob day

Hi @Marcin Oroñ ,Also if you are just trying to get the document’s diagonal I’m not sure you need to construct a dialog—this would get the active documents width and height and return the diagonal:

 

 

app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;
var doc = app.activeDocument;
//the document’s default page width and height 
var dw = doc.documentPreferences.pageWidth;
var dh = doc.documentPreferences.pageHeight;

alert("Document Diagonal = " + getDiagonal(dw,dh) + "  Inches")


/**
* Gets the diagonal of a page 
* @param page width 
* @param page height 
* @return the page diagonal 
*/

function getDiagonal(w,h){
    return Math.sqrt(Math.pow(h,2) + Math.pow(w,2))
}

 

 

Also, pages can have custom width and heights

2 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
January 27, 2022

Hi @Marcin Oroñ ,Also if you are just trying to get the document’s diagonal I’m not sure you need to construct a dialog—this would get the active documents width and height and return the diagonal:

 

 

app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;
var doc = app.activeDocument;
//the document’s default page width and height 
var dw = doc.documentPreferences.pageWidth;
var dh = doc.documentPreferences.pageHeight;

alert("Document Diagonal = " + getDiagonal(dw,dh) + "  Inches")


/**
* Gets the diagonal of a page 
* @param page width 
* @param page height 
* @return the page diagonal 
*/

function getDiagonal(w,h){
    return Math.sqrt(Math.pow(h,2) + Math.pow(w,2))
}

 

 

Also, pages can have custom width and heights

rob day
Community Expert
Community Expert
January 27, 2022

This would return the diagonal of a rectangle:

 

 

$.writeln(getDiagonal(8.5,11))
//returns 13.9014387744578


/**
* Gets the diagonal of a page 
*  page width 
*  page height 
*  the page diagonal 
*/

function getDiagonal(w,h){
    return Math.sqrt(Math.pow(h,2) + Math.pow(w,2))
}