SVG 벡터 이미지로부터 XY 플러터 등의 출력을 위한 gcode로 변환하는 방법을 설명함
여기서는 inkscape 확장모듈과 python 모듈과를 이용하는 2가지 방법을 설명함
inkscape 확장 모듈 사용하기
우선 아래 정보를 이용하여 inkscape를 설치함
- 버전: 0.92 (Draw Pen 확장기능을 위해 최신 버전이 아닌 해당 버전을 꼭 이용해야함)
- https://inkscape.org/release/inkscape-0.92/?latest=1
설치가 완료되면 아래 extention을 설치함
- 다운로드 링크: https://drive.google.com/file/d/1YO8-8guaS3pRbeQzhNKmj_rW7ZZgCtkr/view
- 압축 풀고 나오는 “4xiDraw & km laser” 폴더 아래 파일과 폴더를 inkscape 설치 폴더 아래에 복사함. 복사하는 중에 중복된 파일이 있다고 나오면 덮어 쓰면됨.
Inkpace/share/extensions
Inkspace를 다시 실행해보면 아래와 같이 4xiDraw Tools 메뉴가 보이면 정상적으로 설치가 된것이다.

gcode 생성 방법
inkscape에서 확장 기능 > 4xiDraw Tools > Generate Pen (Servo) Gcode Tool을 열고 아래 항목을 입력해서 gcode를 생성함
펜을 올리고 내리는 서버 모터의 명령이 아래와 같을때를 가정한다.
– M03 S0 : 펜을 내린다 (그리기 모드)
– M03 S40 : 펜을 올린다 (이동 모드)

python 모듈 사용하기 (svg-to-gcode)
python 모듈을 사용하면 python 코드로 변환이 가능해서 자동화 처리에 유리하다.
from svg_to_gcode.svg_parser import parse_file from svg_to_gcode.compiler import Compiler, interfaces from svg_to_gcode.formulas import linear_map class CustomInterface(interfaces.Gcode): def __init__(self): super().__init__() self.fan_speed = 1 # Override the laser_off method such that it also powers off the fan. def laser_off(self): return "M107;\n" + "M5;" # Turn off the fan + turn off the laser # Override the set_laser_power method def set_laser_power(self, power): if power < 0 or power > 1: raise ValueError(f"{power} is out of bounds. Laser power must be given between 0 and 1. " f"The interface will scale it correctly.") return f"M106 S255\n" + f"M3 S{linear_map(0, 255, power)};" # Turn on the fan + change laser power # Instantiate a compiler, specifying the custom interface and the speed at which the tool should move. gcode_compiler = Compiler(CustomInterface, movement_speed=1000, cutting_speed=300, pass_depth=5) curves = parse_file("drawing.svg") # Parse an svg file into geometric curves gcode_compiler.append_curves(curves) gcode_compiler.compile_to_file("drawing.gcode")
더 자세한 설명과 예제는 아래 사이트를 참고한다.
https://pypi.org/project/svg-to-gcode/