This repository has been archived on 2023-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
inkscape-papercraft-unfold-stl/InkScape 0.92.X/fablabchemnitz_papercraft_unfold_binary.py
2020-07-25 01:26:10 +02:00

29 lines
1.1 KiB
Python

import sys
from subprocess import Popen, PIPE
import subprocess
import inkex
import os
class Unfold:
def __init__(self):
stl_filename = inkex.sys.argv[1]
#inkex.debug("stl_filename: "+stl_filename)
if os.name=="nt":
outname = "papercraft_unfold_output.svg"
#remove old file if existent
if os.path.exists(outname):
os.remove(outname)
if os.path.exists("unfold.exe.stackdump"):
os.remove("unfold.exe.stackdump")
#inkex.debug("os.getcwd(): "+os.getcwd())
#inkex.debug(os.path.splitext(stl_filename)[0])
cmd = os.getcwd() + "\\papercraft\\unfold.exe" + " < " + stl_filename + " > " + outname
#inkex.debug("cmd: "+cmd)
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
#inkex.debug(p.communicate())
p.wait()
if p.returncode == 0:
#inkex.debug("OK")
doc = inkex.etree.parse(os.getcwd() + "\\" + outname)
doc.write(inkex.sys.stdout)
if __name__ == '__main__':
gc = Unfold()