kopia lustrzana https://github.com/inkstitch/inkstitch
Add Embroidermodder 2 CSV export
rodzic
ea07ab6f10
commit
4aef2789a2
24
PyEmb.py
24
PyEmb.py
|
@ -144,6 +144,30 @@ class Embroidery:
|
|||
self.pos = stitch
|
||||
return self.str
|
||||
|
||||
def export_csv(self, dbg):
|
||||
self.str = ""
|
||||
self.str += '"#","[THREAD_NUMBER]","[RED]","[GREEN]","[BLUE]","[DESCRIPTION]","[CATALOG_NUMBER]"\n'
|
||||
self.str += '"#","[STITCH_TYPE]","[X]","[Y]"\n'
|
||||
|
||||
lastColor = None
|
||||
colorIndex = 0
|
||||
for stitch in self.coords:
|
||||
if lastColor == None or stitch.color != lastColor:
|
||||
colorIndex += 1
|
||||
self.str += '"$","%d","%d","%d","%d","(null)","(null)"\n' % (
|
||||
colorIndex,
|
||||
int(stitch.color[1:3], 16),
|
||||
int(stitch.color[3:5], 16),
|
||||
int(stitch.color[5:7], 16))
|
||||
if stitch.jumpStitch:
|
||||
self.str += '"*","JUMP","%f","%f"\n' % (stitch.x/10, stitch.y/10)
|
||||
if lastColor != None and stitch.color != lastColor:
|
||||
# not first color choice, add color change record
|
||||
self.str += '"*","COLOR","%f","%f"\n' % (stitch.x/10, stitch.y/10)
|
||||
self.str += '"*","STITCH","%f","%f"\n' % (stitch.x/10, stitch.y/10)
|
||||
lastColor = stitch.color
|
||||
return self.str
|
||||
|
||||
class Test:
|
||||
def __init__(self):
|
||||
emb = Embroidery()
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
<param name="row_spacing_mm" type="float" min="0.01" max="5.00" _gui-text="Row spacing (mm)">0.40</param>
|
||||
<param name="max_stitch_len_mm" type="float" min="0.1" max="10.0" _gui-text="Maximum stitch length (mm)">3.0</param>
|
||||
<param name="preserve_order" type="boolean" _gui-text="Preserve stacking order" description="if false, sorts by color, which saves thread changes. True preserves stacking order, important if you're laying colors over each other.">false</param>
|
||||
<param name="output_format" type="optiongroup" _gui-text="Output file format" appearance="minimal">
|
||||
<_option value="melco">Melco</_option>
|
||||
<_option value="csv">Embroidermodder 2 CSV</_option>
|
||||
</param>
|
||||
<param name="filename" type="string" _gui-text="File">embroider-output.exp</param>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
|
|
34
embroider.py
34
embroider.py
|
@ -328,19 +328,29 @@ class EmbroideryObject:
|
|||
self.patchList = patchList
|
||||
self.row_spacing_px = row_spacing_px
|
||||
|
||||
def emit_melco(self):
|
||||
def emit_file(self, filename, output_format):
|
||||
emb = PyEmb.Embroidery()
|
||||
for patch in self.patchList.patches:
|
||||
jumpStitch = True
|
||||
for stitch in patch.stitches:
|
||||
dbg.write("stitch color %s\n" % patch.color)
|
||||
|
||||
newStitch = PyEmb.Point(stitch.x, -stitch.y)
|
||||
dbg.write("melco stitch color %s\n" % patch.color)
|
||||
newStitch.color = patch.color
|
||||
newStitch.jumpStitch = jumpStitch
|
||||
emb.addStitch(newStitch)
|
||||
|
||||
jumpStitch = False
|
||||
|
||||
emb.translate_to_origin()
|
||||
emb.scale(10.0/pixels_per_millimeter)
|
||||
fp = open("embroider-output.exp", "wb")
|
||||
#fp = open("output.ksm", "wb")
|
||||
fp.write(emb.export_melco(dbg))
|
||||
|
||||
fp = open(filename, "wb")
|
||||
|
||||
if output_format == "melco":
|
||||
fp.write(emb.export_melco(dbg))
|
||||
elif output_format == "csv":
|
||||
fp.write(emb.export_csv(dbg))
|
||||
fp.close()
|
||||
|
||||
def emit_inkscape(self, parent):
|
||||
|
@ -352,7 +362,7 @@ class EmbroideryObject:
|
|||
inkex.addNS('path', 'svg'),
|
||||
{ 'style':simplestyle.formatStyle(
|
||||
{ 'stroke': lastPatch.color,
|
||||
'stroke-width':str(self.row_spacing_px*0.25),
|
||||
'stroke-width':str(self.row_spacing_px*.25),
|
||||
'stroke-dasharray':'0.99, 1.98',
|
||||
'fill': 'none' }),
|
||||
'd':simplepath.formatPath([
|
||||
|
@ -422,6 +432,15 @@ class Embroider(inkex.Effect):
|
|||
choices=["true","false"],
|
||||
dest="preserve_order", default="false",
|
||||
help="Sort by stacking order instead of color")
|
||||
self.OptionParser.add_option("-O", "--output_format",
|
||||
action="store", type="choice",
|
||||
choices=["melco", "csv"],
|
||||
dest="output_format", default="melco",
|
||||
help="File output format")
|
||||
self.OptionParser.add_option("-F", "--filename",
|
||||
action="store", type="string",
|
||||
dest="filename", default="embroider-output.exp",
|
||||
help="Name (and possibly path) of output file")
|
||||
self.patches = []
|
||||
|
||||
def get_sort_order(self, threadcolor):
|
||||
|
@ -570,8 +589,7 @@ class Embroider(inkex.Effect):
|
|||
dbg.write("patch count: %d\n" % len(self.patchList.patches))
|
||||
|
||||
eo = EmbroideryObject(self.patchList, self.row_spacing_px)
|
||||
|
||||
eo.emit_melco()
|
||||
eo.emit_file(self.options.filename, self.options.output_format)
|
||||
|
||||
new_group = inkex.etree.SubElement(self.current_layer,
|
||||
inkex.addNS('g', 'svg'), {})
|
||||
|
|
Ładowanie…
Reference in New Issue