-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr2g.html
70 lines (60 loc) · 4.64 KB
/
r2g.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<script language="javascript" type="text/javascript">
/* <![CDATA[ */
function converttext(){
inputtext = document.getElementById('codeconverter').inputtext.value;
spindletext = document.getElementById('codeconverter').spindletext.value;
cmd = inputtext.split(';')
out = [];
hasPZ = false
for (i in cmd){
line = cmd[i]+';';
isPZ = line.search(/PZ[-0-9]+,[0-9]+;/g);
if (isPZ >=0) {
line = line.split(',')
var Z1 = (parseInt(line[0].match(/[-0-9]+/g))*0.025).toString()
var Z2 = (parseInt(line[1])*0.025).toString()
line = ' ; Z Pen Up = ' + Z1 + ', Z Pen Down = ' + Z2
hasPZ = true
}
line = line.replace(/;/g, '')
line = line.replace(/IN;/g, '')
line = line.replace(/PA;/g, 'G90')
line = line.replace(/!MC1;/g, 'M03 S'+spindletext)
line = line.replace(/!MC0;/g, 'M05')
line = line.replace(/PU;/g, 'G91 G28 Z0')
line = line.replace(/!VZ/g, ' ; !VZ')
/*Convert Tool Speed to Feed Rate*/
line = line.replace(/VS[0-9]+/g, function myFunction1(x){return x.replace(/[0-9]+/g, function myfunction2(y){return (Number(y)*60).toFixed(0);}).replace(/VS/g, 'F');})
/*Convert Pen Down Movement*/
isPD = line.search(/PD[0-9]+,[0-9]+;/g);
if (isPD >=0) {
line = line.replace(/PD[0-9]+,[0-9]+;/g, function myFunction1(x){return x.replace(/[0-9]+/g, function myfunction2(y){return (parseInt(y)*0.025).toFixed(3);}).replace(/PD/g, 'G01 X').replace(/,/g, ' Y');})
if (hasPZ) {line = line.replace(/;/g, ' Z' + Z2)}
}
isPU = line.search(/PU[0-9]+,[0-9]+;/g);
if (isPU >=0) {
line = line.replace(/PU[0-9]+,[0-9]+;/g, function myFunction1(x){return x.replace(/[0-9]+/g, function myfunction2(y){return (parseInt(y)*0.025).toFixed(3);}).replace(/PU/g, 'G01 X').replace(/,/g, ' Y');})
if (hasPZ) {line = line.replace(/;/g, ' Z' + Z1)}
}
out += line +'\n';
}
document.getElementById('codeconverter').outputtext.value = out;
}
/* ]]> */
</script>
<form id="codeconverter">
Spindle Speed (rpm):<br />
<textarea name="spindletext" cols=20 rows=1>
3600
</textarea><br />
Input Text:<br />
<textarea name="inputtext" cols=80 rows=20>
;IN;!MC1;PA;
VS15;!VZ10;!PZ0,6050;PU1035,3699;
!PZ-120,20;PU1035,3699;PD1048,3699;PD1061,3698;PD1074,3698;PD1086,3696;PD1099,3694;PD1112,3692;PD1124,3690;PD1137,3687;PD1149,3684;PD1161,3681;PD1173,3677;PD1185,3673;PD1197,3668;PD1208,3664;PD1220,3658;PD1230,3653;PD1241,3647;PD1252,3641;PD1262,3635;PD1272,3628;PD1282,3621;PD1292,3614;PD1300,3606;PD1309,3599;PD1318,3591;PD1326,3582;PD1334,3574;PD1341,3565;PD1348,3556;PD1355,3547;PD1361,3538;PD1367,3528;PD1372,3519;PD1377,3509;PD1382,3499;PD1386,3489;PD1390,3479;PD1393,3469;PD1396,3458;PD1398,3448;PD1401,3438;PD1402,3427;PD1403,3416;PD1404,3406;PD1404,3395;PD1404,3385;PD1403,3374;PD1402,3364;PD1401,3353;PD1398,3342;PD1396,3332;PD1393,3322;PD1390,3312;PD1386,3302;PD1382,3292;PD1377,3282;PD1372,3272;PD1367,3262;PD1361,3253;PD1355,3244;PD1348,3234;PD1341,3226;PD1334,3217;PD1326,3208;PD1318,3200;PD1309,3192;PD1300,3184;PD1292,3177;PD1282,3170;PD1272,3163;PD1262,3156;PD1252,3150;PD1241,3144;PD1230,3138;PD1220,3132;PD1208,3127;PD1197,3122;PD1185,3118;PD1173,3114;PD1161,3110;PD1149,3106;PD1137,3103;PD1124,3100;PD1112,3098;PD1099,3096;PD1086,3094;PD1074,3093;PD1061,3092;PD1048,3092;PD1035,3092;PD1022,3092;PD1009,3092;PD996,3093;PD984,3094;PD971,3096;PD958,3098;PD946,3100;PD933,3103;PD921,3106;PD908,3110;PD896,3114;PD885,3118;PD873,3122;PD862,3127;PD850,3132;PD839,3138;PD828,3144;PD818,3150;PD808,3156;PD798,3163;PD788,3170;PD778,3177;PD769,3184;PD760,3192;PD752,3200;PD744,3208;PD736,3217;PD729,3226;PD722,3234;PD715,3244;PD709,3253;PD703,3262;PD698,3272;PD692,3282;PD688,3292;PD684,3302;PD680,3312;PD676,3322;PD674,3332;PD671,3342;PD669,3353;PD668,3364;PD666,3374;PD666,3385;PD666,3395;PD666,3406;PD666,3416;PD668,3427;PD669,3438;PD671,3448;PD674,3458;PD676,3469;PD680,3479;PD684,3489;PD688,3499;PD692,3509;PD698,3519;PD703,3528;PD709,3538;PD715,3547;PD722,3556;PD729,3565;PD736,3574;PD744,3582;PD752,3591;PD760,3599;PD769,3606;PD778,3614;PD788,3621;PD798,3628;PD808,3635;PD818,3641;PD828,3647;PD839,3653;PD850,3658;PD862,3664;PD873,3668;PD885,3673;PD896,3677;PD908,3681;PD921,3684;PD933,3687;PD946,3690;PD958,3692;PD971,3694;PD984,3696;PD996,3698;PD1009,3698;PD1022,3699;PD1035,3699;
PU;!MC0;
</textarea><br />
<input onclick="javascript:converttext();" style="margin-top: 5px;" type="button" value="Convert" /><br />
Output Text:<br />
<textarea name="outputtext" cols=80 rows=20></textarea><br />
</form>