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

Math.round size millimeters

Explorer ,
Jul 23, 2019 Jul 23, 2019

Hello everybody

I try to round out the size in millimeters of a rectangle but it does not work.

being a beginner i can not figure  why..

Best regards,

Nick

var document = app.activeDocument;

var mm = 2.834645;

var a = 50.254*mm;

var b = 20.547*mm;

var c = Math.round(a);

var d = Math.round(b);

rectangle = document.activeLayer.pathItems.rectangle(0, 0, c+d, d)

TOPICS
Scripting
665
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

correct answers 1 Correct answer

Advocate , Jul 23, 2019 Jul 23, 2019

var document = app.activeDocument;

var mm = 2.834645;

var a = 50.25;

var b = 20.36;

var c = Math.round(a);

var d = Math.round(b);

rectangle = document.activeLayer.pathItems.rectangle(0, 0, (c+d)*mm, d*mm)

Translate
Adobe
Advocate ,
Jul 23, 2019 Jul 23, 2019

var document = app.activeDocument;

var mm = 2.834645;

var a = 50.25;

var b = 20.36;

var c = Math.round(a);

var d = Math.round(b);

rectangle = document.activeLayer.pathItems.rectangle(0, 0, (c+d)*mm, d*mm)

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
Explorer ,
Jul 23, 2019 Jul 23, 2019

Correct Answer

Thanks for your reply!!!

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

You can use UnitValue class to make conversions between units:

var document = app.activeDocument;

var a = Number(new UnitValue("50.254 mm").as('pt'));

var b = Number(new UnitValue("20.547 mm").as("pt"));

var c = Math.round(a);

var d = Math.round(b);

var rectangle = document.activeLayer.pathItems.rectangle(0, 0, c + d, d);

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
Advocate ,
Jul 23, 2019 Jul 23, 2019
LATEST

Bonjour Lumenn

Je préfaire:

// JavaScript Document for Illustrator

var unite = "mm";

//------

var document = app.activeDocument;

var unit = new UnitValue(1 + " " + unite).as('pt');

var a = 50.25;

var b = 20.36;

var c = Math.round(a);

var d = Math.round(b);

rectangle = document.activeLayer.pathItems.rectangle(0, 0, (c+d)*unit, d*unit);

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