Copy link to clipboard
Copied
Hi,
how to convert the number x and y to the selected unit of the dropdown list...
if I choose mm, the new document created must have 100 x 200 mm
or if I choose cm, the new document created must have 10 x 20 cm
Thanks!
var x = 100; // 100 mm || 10 cm
var y = 200; // 200 mm || 20 cm
var unit = ["Millimeters","Centimeters"];
w = new Window("dialog", "New Document");
d = w.add("group");
choseUnit = d.add("dropdownlist", undefined, unit);
choseUnit.selection = choseUnit.items[0];
btnOk = d.add("button", undefined, "OK");
btnCancel = d.add("button", undefined, "Cancel");
w.show();
unit = choseUnit.selection.text;
var presets = app.startupPresetsList;
var preset = presets[0];
var docPreset = new DocumentPreset();
docPreset.width = x;
docPreset.height = y;
docPreset.colorMode = DocumentColorSpace.CMYK;
docPreset.units = RulerUnits[unit];
var newDoc = app.documents.addDocument(preset, docPreset, false);
Copy link to clipboard
Copied
AI deals with points. So change your first two lines to
var f = 2.835;
var x = 100 * f;
var y = 200 * f;
And that's that.