Copy link to clipboard
Copied
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)
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)
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
Correct Answer ![]()
Thanks for your reply!!!
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more