Copy link to clipboard
Copied
So im writing a script and im having trouble converting a variable into a number.
the relevant parts of the code are as follows,
var cutHeight = sz.add('edittext',undefined,"123.825");
cutHeight.characters = 8;
var layFlatWidth = (slitWidth.text - 4) / 2;
var XX = sz.add('statictext',undefined, "Intials");
XX = sz.add('edittext',undefined, "");
XX.characters = 3;
var repeat = cutHeight;
var repeat2 = (repeat*25.4)
var LF = win.add('group');
var layflat = LF.add('statictext', undefined, "Postition of Fold from the left in mm");
var LFdistance = LF.add('edittext',undefined,"50");
LFdistance.characters = 8;
var wMargin = win.add ('group');
wMargin.alignChildren = 'left';
var marginLeft = wMargin.add('statictext', undefined,"column gap size in mm");
var marginLeftSize =wMargin.add('edittext',undefined,"3.175");
marginLeftSize.characters = 8;
var hMargin= win.add('group');
hMargin.alignChildren = 'right';
var marginRight = hMargin.add('statictext',undefined,"repeat gap size in mm");
var marginRightSize= hMargin.add('edittext',undefined,"3.175");
marginRightSize.characters = 8;
var marginRightSize = parseFloat(marginRightSize)+parseFloat(repeat2);
var sizeInfo = dimL.textFrames.add();
sizeInfo.contents =
'Slit Width: ' + slitWidth.text + 'mm (' + parseFloat(slitWidth.text/25.4).toFixed(3) +'\") \n' +
'Print Width: ' + (slitWidth.text - 2) + 'mm (' + parseFloat((slitWidth.text -2)/25.4).toFixed(3) +'\") \n' +
'Cut Height: ' + (repeat*25.4).toFixed(3) + 'mm (' + parseFloat(repeat).toFixed(3) + '\") \n' +
'Lay Flat Width: ' + (slitWidth.text-8)/2 + 'mm' + ' (' + parseFloat(((slitWidth.text-8)/2)/25.4).toFixed(3) + '\')'+ '\n' +
'Repeat Gap: .125"' + '\n'+
'(' +parseFloat(repeat*25.4).toFixed(3) +'mm -' +marginRightSize.toFixed(3)+'mm ) \n' +
'Column Gap: .125"' + '\n' +
'( ' + parseFloat(slitWidth.text).toFixed(3) +'\mm - ' + parseFloat(slitWidth) + 'mm) \n';
I keep getting NaN for marginRightSize and marginLeftSize+slitWidth.
What am I doing wrong here? how can I fix this?
you need to convert your text fields to numbers
Number(marginRightSize.text)
Copy link to clipboard
Copied
var marginRightSize= hMargin.add('edittext',undefined,"3.175");
marginRightSize.characters = 8;
var marginRightSize = parseFloat(marginRightSize)+parseFloat(repeat2);
So, marginRightSize is a variable under which you store the edittext field - it isn't the content inside. To get the content inside, you'll have to use marginRightSize.text
Also you have already declared marginRightSize 2 lines above, so there is no need to use "var" again.
var marginRightSize= hMargin.add('edittext',undefined,"3.175");
marginRightSize.characters = 8;
marginRightSize = parseFloat(marginRightSize.text)+parseFloat(repeat2);
In your code i can't find any place where you try to parse marginLeftSize.
Copy link to clipboard
Copied
var wMargin = win2.add ('group');
wMargin.alignChildren = 'left';
var marginLeft = wMargin.add('statictext', undefined,"column gap size in mm");
var marginLeftSize =wMargin.add('edittext',undefined,"3.175");
marginLeftSize.characters = 8;
marginLeftSize = parseFloat(marginLeftSize);
var hMargin= win2.add('group');
hMargin.alignChildren = 'right';
var marginRight = hMargin.add('statictext',undefined,"repeat gap size in mm");
var marginRightSize= hMargin.add('edittext',undefined,"3.175");
marginRightSize.characters = 8;
marginRightSize = parseFloat(marginRightSize.text) +parseFloat(repeat2);
updated code. it is still throwing out NaN where the number is displayed
Copy link to clipboard
Copied
I have added .text to leftsize as well now
Copy link to clipboard
Copied
you need to convert your text fields to numbers
Number(marginRightSize.text)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now