wrapper script for CutOptim
This commit is contained in:
parent
ffcb5ed744
commit
b18290e926
0
extensions/fablabchemnitz/cutoptim/linux/CutOptim → extensions/fablabchemnitz/cutoptim/CutOptim
Normal file → Executable file
0
extensions/fablabchemnitz/cutoptim/linux/CutOptim → extensions/fablabchemnitz/cutoptim/CutOptim
Normal file → Executable file
77
extensions/fablabchemnitz/cutoptim/cutoptim.py
Normal file
77
extensions/fablabchemnitz/cutoptim/cutoptim.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Extension for InkScape 1.0
|
||||
|
||||
CutOptim OS Wrapper script to make CutOptim work on Windows and Linux systems without duplicating .inx files
|
||||
|
||||
Author: Mario Voigt / FabLab Chemnitz
|
||||
Mail: mario.voigt@stadtfabrikanten.org
|
||||
Date: 31.08.2020
|
||||
Last patch: 31.08.2020
|
||||
License: GNU GPL v3
|
||||
|
||||
"""
|
||||
|
||||
import inkex
|
||||
import sys
|
||||
import os
|
||||
from lxml import etree
|
||||
|
||||
class CutOptimWrapper(inkex.Effect):
|
||||
def __init__(self):
|
||||
inkex.Effect.__init__(self)
|
||||
args = sys.argv[1:]
|
||||
for arg in args:
|
||||
key=arg.split("=")[0]
|
||||
if len(arg.split("=")) == 2:
|
||||
value=arg.split("=")[1]
|
||||
try:
|
||||
self.arg_parser.add_argument(key, default=key)
|
||||
except:
|
||||
pass #ignore duplicate id arg
|
||||
|
||||
def effect(self):
|
||||
cmd=""
|
||||
if os.name == "nt":
|
||||
cutoptim="CutOptim.exe"
|
||||
else:
|
||||
cutoptim="./CutOptim"
|
||||
#inkex.utils.debug(cmd)
|
||||
cmd += cutoptim
|
||||
for arg in vars(self.options):
|
||||
if arg != "output" and arg != "ids" and arg != "selected_nodes":
|
||||
#inkex.utils.debug(str(arg) + " = " + str(getattr(self.options, arg)))
|
||||
#fix behaviour of "original" arg which does not correctly gets interpreted if set to false
|
||||
if arg == "original" and str(getattr(self.options, arg)) == "false":
|
||||
continue
|
||||
if arg == "input_file":
|
||||
cmd += " --file " + str(getattr(self.options, arg))
|
||||
else:
|
||||
cmd += " --" + arg + " " + str(getattr(self.options, arg))
|
||||
|
||||
if os.name == "nt":
|
||||
cmd += " --output cutoptim.svg"
|
||||
else:
|
||||
cmd += " --output /tmp/cutoptim.svg"
|
||||
#inkex.utils.debug(str(cmd))
|
||||
|
||||
# run CutOptim with the parameters provided
|
||||
with os.popen(cmd, "r") as cutoptim:
|
||||
result = cutoptim.read()
|
||||
|
||||
# check output existence
|
||||
try:
|
||||
stream = open("/tmp/cutoptim.svg", 'r')
|
||||
except FileNotFoundError as e:
|
||||
inkex.utils.debug("There was no SVG output generated. Cannot continue")
|
||||
exit(1)
|
||||
|
||||
# write the generated SVG into InkScape's canvas
|
||||
p = etree.XMLParser(huge_tree=True)
|
||||
doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True))
|
||||
stream.close()
|
||||
doc.write(sys.stdout.buffer)
|
||||
|
||||
if __name__ == '__main__':
|
||||
CutOptimWrapper().run()
|
@ -42,6 +42,6 @@
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx">CutOptim</command>
|
||||
<command location="inx" interpreter="python">cutoptim.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Cutting Optimizer (Nesting)</name>
|
||||
<id>fablabchemnitz.de.cutoptim</id>
|
||||
<param name="unit" type="optiongroup" appearance="combo" gui-text="Unit">
|
||||
<option value="mm">mm</option>
|
||||
<option value="cm">cm</option>
|
||||
<option value="m">m</option>
|
||||
<option value="km">km</option>
|
||||
<option value="in">in</option>
|
||||
<option value="ft">ft</option>
|
||||
<option value="yd">yd</option>
|
||||
<option value="pt">pt</option>
|
||||
<option value="px">px</option>
|
||||
<option value="pc">pc</option>
|
||||
</param>
|
||||
<param name="distance" type="float" min="0" max="10.0" gui-text="Min distance between objects">2.0</param>
|
||||
<param name="max_length" type="float" min="0" max="1000" gui-text="Max length of single segment">1000</param>
|
||||
<param name="optimizing_level" type="int" min="1" max="10" gui-text="Optimizing level">1</param>
|
||||
<param name="original" type="bool" gui-text="Keep original layer in output">false</param>
|
||||
<param name="firstpos" type="optiongroup" appearance="combo" gui-text="Select option for largest element placement: ">
|
||||
<option value="TL">Top Left</option>
|
||||
<option value="TC">Top Center</option>
|
||||
<option value="TR">Top Right</option>
|
||||
<option value="CL">Sheet center</option>
|
||||
<option value="CC">Center Left</option>
|
||||
<option value="CR">Center Right</option>
|
||||
<option value="BL">Bottom Left</option>
|
||||
<option value="BC">Bottom Center</option>
|
||||
<option value="BR">Bottom Right</option>
|
||||
</param>
|
||||
<param name="free_rot" type="bool" gui-text="Allow free rotation of paths, angle parameter not used">true</param>
|
||||
<param name="angle" type="float" min="0" max="180" gui-text="Try rotation by (0 no rotation allowed)">0</param>
|
||||
<param name="nested" type="bool" gui-text="Attach nested path to the bigger one">true</param>
|
||||
<param name="debug_file" type="bool" gui-text="Debug file generation">true</param>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz">
|
||||
<submenu name="Nesting/Cut Optimization"/>
|
||||
</submenu>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx">CutOptim.exe</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
Reference in New Issue
Block a user