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

Indesign CS6 size validation, js

Participant ,
Aug 08, 2019 Aug 08, 2019

Copy link to clipboard

Copied

Hi,

I am checking indesign document size through the script comparing it to order specs, and it works great with standard numbers (if I can call them that way), like 3.5x2, 4x6, 2.125x2.125, etc.

But when I get strange numbers, like 1.8x4.1, it tells me that size is wrong when size is correct. Why would it matter what kind of number it is and how I can make it work?

Here is my script (I check both orientations):

if((myXmlWidth == myPageWidth && myXmlHeight == myPageHeight) || (myXmlWidth == myPageHeight && myXmlHeight == myPageWidth)){

}else{

alert("Incorrect document size.");

exit();

}

Thank you

Yulia

TOPICS
Scripting

Views

484

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 ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Weird indeed. Might this be a rounding issue ?

InDesign may display a rounded value while the geometric bounds may return non rounded values.

Eventually 1.99999 isn't 2

FWIW

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
Guru ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Here's a function which I use to deal with the rounding error:

function RoundWithDecimal(number, decimals) {

    var multiplier = Math.pow(10, decimals);

    return Math.round(number * multiplier) / multiplier;

}

gb = frame.geometricBounds;

left = RoundWithDecimal(gb[1], 3);

right = RoundWithDecimal(gb[3], 3);

top = RoundWithDecimal(gb[0], 3);

bottom = RoundWithDecimal(gb[2], 3);

width = right - left;

height = bottom - top;

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
Participant ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

LATEST

Thank you, Kasyan,

Your approach gave different idea that worked for me too. I am comparing them like strings instead of numbers now:

if((docNameSize == myPageWidth+"x"+myPageHeight) || (docNameSize == myPageHeight+"x"+myPageWidth)){

}else{

alert("Incorrect document size. \nReload xml and InDesign file and re-apply template script.");

exit();

}

Thank you

Yulia

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