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 1.0/fablabchemnitz_papercraft_u...

37 lines
1.5 KiB
Python

import sys
from subprocess import Popen
import subprocess
import inkex
import os
from lxml import etree
class Unfold(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
stl_filename = sys.argv[1]
#inkex.utils.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")
#convert the STL to have a binary one and wait until conversion finished before running papercraft
cmd = os.getcwd() + "\\papercraft\\STLConverter.exe" + " \"" + stl_filename + "\""
p = Popen(cmd, shell=True)
#inkex.utils.debug(cmd)
#inkex.utils.debug("os.getcwd(): "+os.getcwd())
#inkex.utils.debug(os.path.splitext(stl_filename)[0])
p.wait()
cmd2 = os.getcwd() + "\\papercraft\\unfold.exe" + " < \"" + os.path.splitext(stl_filename)[0] + "-binary.stl\" > " + outname
#inkex.utils.debug("cmd2: "+cmd2)
p2 = Popen(cmd2, shell=True)
#inkex.utils.debug(p2.communicate())
p2.wait()
if p2.returncode == 0:
#inkex.utils.debug("OK")
doc = etree.parse(os.getcwd() + "\\" + outname)
doc.write(sys.stdout.buffer)
if __name__ == '__main__':
gc = Unfold()