Browse Source

laser engraver scripts now included from gitea at compile time

Thomas Buck 1 year ago
parent
commit
c0d501ce90
2 changed files with 35 additions and 641 deletions
  1. 26
    641
      input/projects/laser-engraver.md
  2. 9
    0
      macros.py

+ 26
- 641
input/projects/laser-engraver.md View File

3
 parent: projects
3
 parent: projects
4
 git: https://git.xythobuz.de/thomas/marlin/src/branch/laser-engraver
4
 git: https://git.xythobuz.de/thomas/marlin/src/branch/laser-engraver
5
 date: 2022-11-25
5
 date: 2022-11-25
6
+update: 2023-01-02
6
 comments: true
7
 comments: true
7
 ---
8
 ---
8
 
9
 
273
 But my script below should work for all variants I have seen up to now.
274
 But my script below should work for all variants I have seen up to now.
274
 
275
 
275
 <pre class="sh_python">
276
 <pre class="sh_python">
276
-#!/usr/bin/env python
277
-
278
-import sys
279
-
280
-if len(sys.argv) < 3:
281
-    print("Usage:")
282
-    print("    " + sys.argv[0] + " input.nc output.gcode")
283
-    sys.exit(1)
284
-
285
-in_file = sys.argv[1]
286
-out_file = sys.argv[2]
287
-
288
-power = ""
289
-speed = ""
290
-mode_g0 = True
291
-
292
-def add_spaces(s):
293
-    prev = ' '
294
-    r = ""
295
-    for c in s:
296
-        if str(prev).isdigit() and str(c).isalpha():
297
-            r = r + " "
298
-        r = r + c
299
-        prev = c
300
-    return r
301
-
302
-with open(in_file, 'r') as fi, open(out_file, 'w') as fo:
303
-    for line in fi:
304
-        if line.startswith("S"):
305
-            power = " " + line.rstrip()
306
-        elif line.startswith("F"):
307
-            speed = " " + line.rstrip()
308
-        else:
309
-            s = add_spaces(line.rstrip())
310
-            if line.startswith("G1"):
311
-                mode_g0 = False
312
-                s += power
313
-                s += speed
314
-            elif line.startswith("G0"):
315
-                mode_g0 = True
316
-                s += power
317
-                if (power != " S0") and (power != ""):
318
-                    print("Warning: G0 move with power not zero!" + power)
319
-            elif line.startswith("X") or line.startswith("Y"):
320
-                if mode_g0:
321
-                    s = "G0 " + s
322
-                    s += power
323
-                    if (power != " S0") and (power != ""):
324
-                        print("Warning: G0 move with power not zero!" + power)
325
-                else:
326
-                    s = "G1 " + s
327
-                    s += power
328
-                    s += speed
329
-            s += "\n"
330
-            fo.write(s)
277
+<!--%
278
+include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/convert_lasergrbl.py")
279
+%-->
331
 </pre>
280
 </pre>
332
 
281
 
282
+You can also find this script [on my Gitea server](https://git.xythobuz.de/thomas/gcode-tools/src/branch/master/tools/convert_lasergrbl.py).
283
+
333
 Here is my first attempt of cutting a vector outline of an image out of a piece of paper.
284
 Here is my first attempt of cutting a vector outline of an image out of a piece of paper.
334
 I used Marlins default speed and a PWM setting of 150 out of 255.
285
 I used Marlins default speed and a PWM setting of 150 out of 255.
335
 
286
 
386
 I copy this file to the SD card, start it, and just abort it when I'm done with the preparations.
337
 I copy this file to the SD card, start it, and just abort it when I'm done with the preparations.
387
 
338
 
388
 <pre class="sh_python">
339
 <pre class="sh_python">
389
-#!/usr/bin/env python
390
-
391
-import sys
392
-
393
-if len(sys.argv) < 3:
394
-    print("Usage:")
395
-    print("    " + sys.argv[0] + " input.nc output.gcode")
396
-    sys.exit(1)
397
-
398
-in_file = sys.argv[1]
399
-out_file = sys.argv[2]
400
-
401
-x_min = None
402
-x_max = None
403
-y_min = None
404
-y_max = None
405
-mode_g1 = False
406
-
407
-pwr = 1
408
-iterations = 100
409
-speed = 3000
410
-
411
-with open(in_file, 'r') as fi, open(out_file, 'w') as fo:
412
-    for line in fi:
413
-        if line.startswith("G1"):
414
-            mode_g1 = True
415
-        elif line.startswith("G0"):
416
-            mode_g1 = False
417
-
418
-        if mode_g1:
419
-            x_pos = line.find("X")
420
-            if x_pos > -1:
421
-                x_str = line[x_pos + 1:]
422
-                x_num = float(x_str.split()[0])
423
-                #print("found x: " + str(x_num))
424
-                if (x_min == None) or (x_num < x_min):
425
-                    x_min = x_num
426
-                if (x_max == None) or (x_num > x_max):
427
-                    x_max = x_num
428
-
429
-            y_pos = line.find("Y")
430
-            if y_pos > -1:
431
-                y_str = line[y_pos + 1:]
432
-                y_num = float(y_str.split()[0])
433
-                #print("found y: " + str(y_num))
434
-                if (y_min == None) or (y_num < y_min):
435
-                    y_min = y_num
436
-                if (y_max == None) or (y_num > y_max):
437
-                    y_max = y_num
438
-
439
-    print("x_min: " + str(x_min))
440
-    print("x_max: " + str(x_max))
441
-    print("y_min: " + str(y_min))
442
-    print("y_max: " + str(y_max))
443
-
444
-    pos = [
445
-        ( x_min, y_min ),
446
-        ( x_max, y_min ),
447
-        ( x_max, y_max ),
448
-        ( x_min, y_max ),
449
-    ]
450
-
451
-    def write(s):
452
-        #print(s)
453
-        fo.write(s + "\n")
454
-
455
-    # header
456
-    write("G90")
457
-    write("M3 I")
458
-    write("M3 S0")
459
-
460
-    write("G0 X" + str(x_min) + " Y" + str(y_min) + " S0 F" + str(speed))
461
-
462
-    for i in range(0, iterations):
463
-        for x, y in pos:
464
-            write("G1 X" + str(x) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed))
465
-
466
-    write("M5")
467
-    write("G0 X" + str(x_min) + " Y" + str(y_min) + " S0 F" + str(speed))
340
+<!--%
341
+include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/outline_gcode.py")
342
+%-->
468
 </pre>
343
 </pre>
469
 
344
 
345
+You can also find this script [on my Gitea server](https://git.xythobuz.de/thomas/gcode-tools/src/branch/master/tools/outline_gcode.py).
346
+
470
 I also did some experimentation with programatically generating G-Code myself, using a simple Python script as well.
347
 I also did some experimentation with programatically generating G-Code myself, using a simple Python script as well.
471
 It's drawing a grid for reference on the base plate of the machine, including numerical position indicators.
348
 It's drawing a grid for reference on the base plate of the machine, including numerical position indicators.
472
 
349
 
473
 <pre class="sh_python">
350
 <pre class="sh_python">
474
-#!/usr/bin/env python
475
-
476
-filename = "grid.gcode"
477
-w = 200
478
-h = 280
479
-d = 10
480
-pwr = 100
481
-speed_g0 = 3000
482
-speed_g1 = 1000
483
-
484
-digits = [
485
-    [
486
-        # 0
487
-        (0.0, 0.0),
488
-        (0.0, 1.0),
489
-        (1.0, 1.0),
490
-        (1.0, 0.0),
491
-        (0.0, 0.0)
492
-    ], [
493
-        # 1
494
-        (0.5, 0.0),
495
-        (0.5, 1.0)
496
-    ], [
497
-        # 2
498
-        (0.0, 1.0),
499
-        (1.0, 1.0),
500
-        (1.0, 0.5),
501
-        (0.0, 0.5),
502
-        (0.0, 0.0),
503
-        (1.0, 0.0),
504
-    ], [
505
-        # 3
506
-        (0.0, 1.0),
507
-        (1.0, 1.0),
508
-        (1.0, 0.5),
509
-        (0.0, 0.5),
510
-        (1.0, 0.5),
511
-        (1.0, 0.0),
512
-        (0.0, 0.0),
513
-    ], [
514
-        # 4
515
-        (0.0, 1.0),
516
-        (0.0, 0.5),
517
-        (1.0, 0.5),
518
-        (1.0, 1.0),
519
-        (1.0, 0.0),
520
-    ], [
521
-        # 5
522
-        (1.0, 1.0),
523
-        (0.0, 1.0),
524
-        (0.0, 0.5),
525
-        (1.0, 0.5),
526
-        (1.0, 0.0),
527
-        (0.0, 0.0),
528
-    ], [
529
-        # 6
530
-        (1.0, 1.0),
531
-        (0.0, 1.0),
532
-        (0.0, 0.0),
533
-        (1.0, 0.0),
534
-        (1.0, 0.5),
535
-        (0.0, 0.5),
536
-    ], [
537
-        # 7
538
-        (0.0, 1.0),
539
-        (1.0, 1.0),
540
-        (1.0, 0.0),
541
-    ], [
542
-        # 8
543
-        (1.0, 0.5),
544
-        (1.0, 1.0),
545
-        (0.0, 1.0),
546
-        (0.0, 0.5),
547
-        (1.0, 0.5),
548
-        (1.0, 0.0),
549
-        (0.0, 0.0),
550
-        (0.0, 0.5),
551
-    ], [
552
-        # 9
553
-        (1.0, 0.5),
554
-        (1.0, 1.0),
555
-        (0.0, 1.0),
556
-        (0.0, 0.5),
557
-        (1.0, 0.5),
558
-        (1.0, 0.0),
559
-        (0.0, 0.0),
560
-    ]
561
-]
562
-
563
-font_w = 1.5
564
-font_h = 3.0
565
-font_d = 0.5
566
-
567
-def draw_digit(f, i, sx, sy, ox, oy):
568
-    dig = digits[i]
569
-    n = 0
570
-    for p in dig:
571
-        x, y = p
572
-        s = ""
573
-
574
-        if n == 0:
575
-            s += "G0 S0 F" + str(speed_g0)
576
-        else:
577
-            s += "G1 S" + str(pwr) + " F" + str(speed_g1)
578
-
579
-        s += " X" + str(ox + sx * x)
580
-        s += " Y" + str(oy + sy * y)
581
-
582
-        print(s)
583
-        f.write(s + "\n")
584
-        n += 1
585
-
586
-    return s
587
-
588
-with open(filename, 'w') as f:
589
-    def write(s):
590
-        print(s)
591
-        f.write(s + "\n")
592
-
593
-    # header
594
-    write("G90")
595
-    write("M3 I")
596
-    write("M3 S0")
597
-
598
-    # first line is not having the power applied
599
-    # so just draw it twice
600
-    # TODO why?
601
-    write("G0 X0 Y0 S0 F" + str(speed_g0))
602
-    write("G1 X0 Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
603
-
604
-    # vertical lines
605
-    for x in range(0, w + d, d):
606
-        write("G0 X" + str(x) + " Y0 S0 F" + str(speed_g0))
607
-        write("G1 X" + str(x) + " Y" + str(h) + " S" + str(pwr) + " F" + str(speed_g1))
608
-
609
-    # horizontal lines
610
-    for y in range(0, h + d, d):
611
-        write("G0 X0 Y" + str(y) + " S0 F" + str(speed_g0))
612
-        write("G1 X" + str(w) + " Y" + str(y) + " S" + str(pwr) + " F" + str(speed_g1))
613
-
614
-    for x in range(0, w, d):
615
-        n = int(x / 10)
616
-        if n >= 10:
617
-            draw_digit(f, int(n / 10), font_w, font_h, font_d + x, font_d)
618
-            draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w + x, font_d)
619
-        else:
620
-            draw_digit(f, n, font_w, font_h, font_d + x, font_d)
621
-
622
-    for y in range(d, h, d):
623
-        n = int(y / 10)
624
-        if n >= 10:
625
-            draw_digit(f, int(n / 10), font_w, font_h, font_d, font_d + y)
626
-            draw_digit(f, int(n % 10), font_w, font_h, 2 * font_d + font_w, font_d + y)
627
-        else:
628
-            draw_digit(f, n, font_w, font_h, font_d, font_d + y)
629
-
630
-    # footer
631
-    write("M5")
632
-    write("G0 X0 Y0 F" + str(speed_g0))
351
+<!--%
352
+include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/grid_gcode.py")
353
+%-->
633
 </pre>
354
 </pre>
634
 
355
 
356
+You can also find this script [on my Gitea server](https://git.xythobuz.de/thomas/gcode-tools/src/branch/master/generators/grid_gcode.py).
357
+
635
 I like the idea but unfortunately it has some problems in practice.
358
 I like the idea but unfortunately it has some problems in practice.
636
 When changing the focus level of my laser diode, it's very easy to also change the offset in the X and Y axes.
359
 When changing the focus level of my laser diode, it's very easy to also change the offset in the X and Y axes.
637
 So the grid is not properly aligned for long.
360
 So the grid is not properly aligned for long.
651
 As I grew tired of removing, flashing and re-inserting of the SD card, I decided to also write a quick little G-Code sender for the serial port.
374
 As I grew tired of removing, flashing and re-inserting of the SD card, I decided to also write a quick little G-Code sender for the serial port.
652
 
375
 
653
 <pre class="sh_python">
376
 <pre class="sh_python">
654
-#!/usr/bin/env python
655
-
656
-import sys
657
-import serial
658
-
659
-if len(sys.argv) < 3:
660
-    print("Usage:")
661
-    print("    " + sys.argv[0] + " /dev/serial/port input.gcode")
662
-    sys.exit(1)
663
-
664
-port_file = sys.argv[1]
665
-in_file = sys.argv[2]
666
-
667
-port = serial.Serial()
668
-port.port = port_file
669
-port.baudrate = 115200
670
-#port.timeout = 0.0
671
-
672
-max_cmd_buffer = 5
673
-counter = 0
674
-
675
-def connect_serial():
676
-    try:
677
-        port.open()
678
-        if port.is_open:
679
-            print("connected to: " + port_file)
680
-        else:
681
-            print("error connecting to " + port_file)
682
-            sys.exit(1)
683
-    except serial.serialutil.SerialException:
684
-        print("error connecting to " + port_file)
685
-        sys.exit(1)
686
-
687
-def wait_for_text(s):
688
-    while True:
689
-        response = port.read_until().decode().strip()
690
-        print("rx w: " + response)
691
-        if response.startswith(s):
692
-            break
693
-        elif response.startswith("Error"):
694
-            print(response)
695
-            print("CNC returned error. aborting.")
696
-            abort_print(False)
697
-            port.close()
698
-            sys.exit(1)
699
-
700
-def abort_print(wait_for_oks = True):
701
-    global counter
702
-
703
-    print("tx: M5")
704
-    port.write("M5\n".encode())
705
-    counter += 1
706
-
707
-    print("tx: G0 X0 Y0 F1000")
708
-    port.write("G0 X0 Y0 F1000\n".encode())
709
-    counter += 1
710
-
711
-    if wait_for_oks:
712
-        while counter > 0:
713
-            wait_for_text("ok")
714
-            counter -= 1
715
-
716
-def send_file(f):
717
-    global counter
718
-
719
-    for line in f:
720
-        if ";" in line:
721
-            line = line.split(";")[0]
722
-
723
-        line = line.strip()
724
-
725
-        if len(line) <= 0:
726
-            print("skipping empty line")
727
-            continue
728
-
729
-        print("tx: " + line)
730
-        tx = line.encode() + b'\n'
731
-        port.write(tx)
732
-
733
-        counter += 1
734
-        print("cnt=" + str(counter))
735
-
736
-        while counter >= max_cmd_buffer:
737
-            response = port.read_until().decode().strip()
738
-            #print("rx: " + response)
739
-            if response.startswith("ok"):
740
-                counter -= 1
741
-                print("cnt=" + str(counter))
742
-            elif response.startswith("Error"):
743
-                print(response)
744
-                print("CNC returned error. aborting.")
745
-                abort_print(False)
746
-                port.close()
747
-                sys.exit(1)
748
-
749
-def main():
750
-    connect_serial()
751
-
752
-    print("waiting for CNC to reset")
753
-    wait_for_text("start")
754
-
755
-    print("auto-homing after reset")
756
-    print("tx: G28")
757
-    port.write("G28\n".encode())
758
-    wait_for_text("ok")
759
-
760
-    try:
761
-        with open(in_file, 'r') as f:
762
-            send_file(f)
763
-
764
-        while counter > 0:
765
-            wait_for_text("ok")
766
-            counter -= 1
767
-    except KeyboardInterrupt:
768
-        print("user interrupt. aborting.")
769
-        abort_print(True)
770
-
771
-    port.close()
772
-
773
-if __name__ == '__main__':
774
-    main()
377
+<!--%
378
+include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/send_gcode.py")
379
+%-->
775
 </pre>
380
 </pre>
776
 
381
 
382
+You can also find this script [on my Gitea server](https://git.xythobuz.de/thomas/gcode-tools/src/branch/master/tools/send_gcode.py).
383
+
777
 Of course it's important to use the proper speed, power and number of iterations for each object to cut.
384
 Of course it's important to use the proper speed, power and number of iterations for each object to cut.
778
 Not enough power or iterations, or too high of a speed, and the object will still be part of the stock material.
385
 Not enough power or iterations, or too high of a speed, and the object will still be part of the stock material.
779
 Too much power or iterations and not only the object will be cut, but also the base plate below.
386
 Too much power or iterations and not only the object will be cut, but also the base plate below.
782
 I then made another Python script go generate G-Code for a cutting test, varying speed and number of iterations.
389
 I then made another Python script go generate G-Code for a cutting test, varying speed and number of iterations.
783
 
390
 
784
 <pre class="sh_python">
391
 <pre class="sh_python">
785
-#!/usr/bin/env python
786
-
787
-# general settings
788
-filename = "cut_test.gcode"
789
-pwr = 255
790
-pwr_num = 150
791
-speed_g0 = 3000
792
-speed_g1_num = 500
793
-
794
-# settings of single test shape
795
-width = 10
796
-height = 10
797
-dist = 2
798
-
799
-# range for tests
800
-iterations = [ 5, 10, 15, 20 ]
801
-speeds_g1 = [ 1000, 500, 200 ]
802
-
803
-def drawSquare(w, h, x, y, speed_g1):
804
-    write("G0 X" + str(x) + " Y" + str(y) + " S0 F" + str(speed_g0))
805
-    square = [
806
-        ( x + w, y ),
807
-        ( x + w, y + h ),
808
-        ( x, y + h ),
809
-        ( x, y ),
810
-    ]
811
-    for xp, yp in square:
812
-        write("G1 X" + str(xp) + " Y" + str(yp) + " S" + str(pwr) + " F" + str(speed_g1))
813
-
814
-def drawHeart(w, h, x, y, speed_g1):
815
-    heart = [
816
-        ( 0.0, 5.0 / 8.0 ),
817
-        ( 0.0, 6.0 / 8.0 ),
818
-        ( 0.1, 7.0 / 8.0 ),
819
-        ( 0.2, 8.0 / 8.0 ),
820
-        ( 0.3, 8.0 / 8.0 ),
821
-        ( 0.4, 7.0 / 8.0 ),
822
-        ( 0.5, 6.0 / 8.0 ),
823
-        ( 0.6, 7.0 / 8.0 ),
824
-        ( 0.7, 8.0 / 8.0 ),
825
-        ( 0.8, 8.0 / 8.0 ),
826
-        ( 0.9, 7.0 / 8.0 ),
827
-        ( 1.0, 6.0 / 8.0 ),
828
-        ( 1.0, 5.0 / 8.0 ),
829
-        ( 0.9, 4.0 / 8.0 ),
830
-        ( 0.8, 3.0 / 8.0 ),
831
-        ( 0.7, 2.0 / 8.0 ),
832
-        ( 0.6, 1.0 / 8.0 ),
833
-        ( 0.5, 0.0 / 8.0 ),
834
-        ( 0.4, 1.0 / 8.0 ),
835
-        ( 0.3, 2.0 / 8.0 ),
836
-        ( 0.2, 3.0 / 8.0 ),
837
-        ( 0.1, 4.0 / 8.0 ),
838
-        ( 0.0, 5.0 / 8.0 )
839
-    ]
840
-    write("G0 X" + str(x + heart[0][0] * w) + " Y" + str(y + heart[0][1] * h) + " S0 F" + str(speed_g0))
841
-    for xp, yp in heart:
842
-        write("G1 X" + str(x + xp * w) + " Y" + str(y + yp * h) + " S" + str(pwr) + " F" + str(speed_g1))
843
-
844
-def drawShape(w, h, x, y, speed_g1):
845
-    #drawSquare(w, h, x, y, speed_g1)
846
-    drawHeart(w, h, x, y, speed_g1)
847
-
848
-digits = [
849
-    [
850
-        # 0
851
-        (0.0, 0.0),
852
-        (0.0, 1.0),
853
-        (1.0, 1.0),
854
-        (1.0, 0.0),
855
-        (0.0, 0.0)
856
-    ], [
857
-        # 1
858
-        (0.5, 0.0),
859
-        (0.5, 1.0)
860
-    ], [
861
-        # 2
862
-        (0.0, 1.0),
863
-        (1.0, 1.0),
864
-        (1.0, 0.5),
865
-        (0.0, 0.5),
866
-        (0.0, 0.0),
867
-        (1.0, 0.0),
868
-    ], [
869
-        # 3
870
-        (0.0, 1.0),
871
-        (1.0, 1.0),
872
-        (1.0, 0.5),
873
-        (0.0, 0.5),
874
-        (1.0, 0.5),
875
-        (1.0, 0.0),
876
-        (0.0, 0.0),
877
-    ], [
878
-        # 4
879
-        (0.0, 1.0),
880
-        (0.0, 0.5),
881
-        (1.0, 0.5),
882
-        (1.0, 1.0),
883
-        (1.0, 0.0),
884
-    ], [
885
-        # 5
886
-        (1.0, 1.0),
887
-        (0.0, 1.0),
888
-        (0.0, 0.5),
889
-        (1.0, 0.5),
890
-        (1.0, 0.0),
891
-        (0.0, 0.0),
892
-    ], [
893
-        # 6
894
-        (1.0, 1.0),
895
-        (0.0, 1.0),
896
-        (0.0, 0.0),
897
-        (1.0, 0.0),
898
-        (1.0, 0.5),
899
-        (0.0, 0.5),
900
-    ], [
901
-        # 7
902
-        (0.0, 1.0),
903
-        (1.0, 1.0),
904
-        (1.0, 0.0),
905
-    ], [
906
-        # 8
907
-        (1.0, 0.5),
908
-        (1.0, 1.0),
909
-        (0.0, 1.0),
910
-        (0.0, 0.5),
911
-        (1.0, 0.5),
912
-        (1.0, 0.0),
913
-        (0.0, 0.0),
914
-        (0.0, 0.5),
915
-    ], [
916
-        # 9
917
-        (1.0, 0.5),
918
-        (1.0, 1.0),
919
-        (0.0, 1.0),
920
-        (0.0, 0.5),
921
-        (1.0, 0.5),
922
-        (1.0, 0.0),
923
-        (0.0, 0.0),
924
-    ]
925
-]
926
-
927
-font_w = 1.5
928
-font_h = 3.0
929
-font_d = 0.5
930
-
931
-def draw_digit(f, i, size_x, size_y, off_x, off_y):
932
-    dig = digits[i]
933
-    n = 0
934
-    for p in dig:
935
-        x, y = p
936
-        s = ""
937
-
938
-        if n == 0:
939
-            s += "G0 S0 F" + str(speed_g0)
940
-        else:
941
-            s += "G1 S" + str(pwr_num) + " F" + str(speed_g1_num)
942
-
943
-        s += " X" + str(off_x + size_x * x)
944
-        s += " Y" + str(off_y + size_y * y)
945
-
946
-        print(s)
947
-        f.write(s + "\n")
948
-        n += 1
949
-
950
-    return s
951
-
952
-def draw_number(f, n, x, y):
953
-    if n >= 1000:
954
-        draw_digit(f, int(n / 1000),       font_w, font_h, x,                         y)
955
-        draw_digit(f, int((n / 100)) % 10, font_w, font_h, x + font_d + font_w,       y)
956
-        draw_digit(f, int((n / 10) % 10),  font_w, font_h, x + 2 * (font_d + font_w), y)
957
-        draw_digit(f, int(n % 10),         font_w, font_h, x + 3 * (font_d + font_w), y)
958
-    elif n >= 100:
959
-        draw_digit(f, int(n / 100),       font_w, font_h, x,                         y)
960
-        draw_digit(f, int((n / 10) % 10), font_w, font_h, x + font_d + font_w,       y)
961
-        draw_digit(f, int(n % 10),        font_w, font_h, x + 2 * (font_d + font_w), y)
962
-    elif n >= 10:
963
-        draw_digit(f, int(n / 10), font_w, font_h, x,                   y)
964
-        draw_digit(f, int(n % 10), font_w, font_h, x + font_d + font_w, y)
965
-    else:
966
-        draw_digit(f, n, font_w, font_h, x, y)
967
-
968
-with open(filename, 'w') as f:
969
-    def write(s):
970
-        print(s)
971
-        f.write(s + "\n")
972
-
973
-    # header
974
-    #write("G28")
975
-    write("G90")
976
-    write("M3 I")
977
-    write("M3 S0")
978
-    write("")
979
-
980
-    # first line is not having the power applied
981
-    # TODO
982
-    write("G0 X0 Y0 S0 F" + str(speed_g0))
983
-    write("G1 X1 Y0 S1 F" + str(speeds_g1[0]))
984
-    write("G0 X0 Y0 S0 F" + str(speed_g0))
985
-    write("G1 X0 Y1 S1 F" + str(speeds_g1[0]))
986
-    write("G0 X0 Y0 S0 F" + str(speed_g0))
987
-
988
-    max_num_str_len = 4
989
-    str_w = (max_num_str_len * font_w) + ((max_num_str_len - 1) * font_d)
990
-
991
-    write("; iterations")
992
-    for i in range(0, len(iterations)):
993
-        write("; " + str(iterations[i]))
994
-        draw_number(f, iterations[i], (width + str_w) / 2.0 + dist + i * (width + dist), 0)
995
-    write("")
996
-
997
-    write("; speeds")
998
-    for i in range(0, len(speeds_g1)):
999
-        write("; " + str(speeds_g1[i]))
1000
-        draw_number(f, speeds_g1[i], 0, (height + font_h) / 2.0 + dist + i * (height + dist))
1001
-
1002
-    for i in range(0, len(speeds_g1)):
1003
-        for j in range(0, len(iterations)):
1004
-            write("; speed=" + str(speeds_g1[i]) + " n=" + str(iterations[j]))
1005
-            for k in range(0, iterations[j]):
1006
-                drawShape(width, height, str_w + dist + j * (width + dist), font_h + dist + i * (height + dist), speeds_g1[i])
1007
-            write("")
1008
-
1009
-    # footer
1010
-    write("M5")
1011
-    write("G0 X0 Y0 F" + str(speed_g0))
392
+<!--%
393
+include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/cut_test_gcode.py")
394
+%-->
1012
 </pre>
395
 </pre>
1013
 
396
 
397
+You can also find this script [on my Gitea server](https://git.xythobuz.de/thomas/gcode-tools/src/branch/master/generators/cut_test_gcode.py).
398
+
1014
 I'm drawing digits again, like in the Grid G-Code generator above.
399
 I'm drawing digits again, like in the Grid G-Code generator above.
1015
 It seems I need to create some kind of library or so if I continue this route of generating G-Code.
400
 It seems I need to create some kind of library or so if I continue this route of generating G-Code.
1016
 
401
 

+ 9
- 0
macros.py View File

323
 
323
 
324
 def restRequest(url):
324
 def restRequest(url):
325
     response = urllib.urlopen(url)
325
     response = urllib.urlopen(url)
326
+    if response.getcode() != 200:
327
+        raise Exception("invalid response code", response.getcode())
326
     data = json.loads(response.read())
328
     data = json.loads(response.read())
327
     return data
329
     return data
328
 
330
 
370
         print("<li><a href=\"" + a["browser_download_url"] + "\">" + a["name"] + "</a>" + ss)
372
         print("<li><a href=\"" + a["browser_download_url"] + "\">" + a["name"] + "</a>" + ss)
371
     print("</ul></div>")
373
     print("</ul></div>")
372
 
374
 
375
+def include_url(url):
376
+    response = urllib.urlopen(url)
377
+    if response.getcode() != 200:
378
+        raise Exception("invalid response code", response.getcode())
379
+    data = response.read()
380
+    print data,
381
+
373
 # -----------------------------------------------------------------------------
382
 # -----------------------------------------------------------------------------
374
 # preconvert hooks
383
 # preconvert hooks
375
 # -----------------------------------------------------------------------------
384
 # -----------------------------------------------------------------------------

Loading…
Cancel
Save