Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions laserCut_BendWoodCutsPattern.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3

"""
A Inkscape extension to generate a pattern that allows to bend wood or MDF one it is laser cut.
"""

import sys, copy
import inkex, simpletransform
import simplestyle
import inkex
import math
from lxml import etree

class BendWoodCutsPattern(inkex.Effect):
height = -1.0

def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option('-w', '--width', action='store', type='float', dest='width', default=10, help='Width (mm)')
self.OptionParser.add_option('-x', '--height', action='store', type='float', dest='height', default=100, help='Height (mm)')
self.OptionParser.add_option('-H', '--horizontalLineSeparation', action='store', type='float', dest='horizontalLineSeparation', default=1, help='Horizontal Line Separation (mm)')
self.OptionParser.add_option('-v', '--verticalLineSeparation', action='store', type='float', dest='verticalLineSeparation', default=3, help='Vertical Line Separation (mm)')
self.OptionParser.add_option('-j', '--maxLineLength', action='store', type='float', dest='maxLineLength', default=30, help='Max Line Length (mm)')
self.OptionParser.add_option('-t', '--addInitMarks', action='store', type='string', dest='addInitMarks', default="false", help='Add Init Marks')
self.OptionParser.add_option('-g', '--groupLines', action='store', type='string', dest='groupLines', default="false", help='Group Lines')
self.arg_parser.add_argument('--width', type=float, default=10, help='Width (mm)')
self.arg_parser.add_argument('--height', type=float, default=100, help='Height (mm)')
self.arg_parser.add_argument('--horizontalLineSeparation', type=float, default=1, help='Horizontal Line Separation (mm)')
self.arg_parser.add_argument('--verticalLineSeparation', type=float, default=3, help='Vertical Line Separation (mm)')
self.arg_parser.add_argument('--maxLineLength', type=float, default=30, help='Max Line Length (mm)')
self.arg_parser.add_argument('--addInitMarks', default="false", help='Add Init Marks')
self.arg_parser.add_argument('--groupLines', default="false", help='Group Lines')

#draw an SVG line segment between the given (raw) points
def draw_SVG_line(self, (x1, y1), (x2, y2), parent):
def draw_SVG_line(self, x1, y1, x2, y2, parent):

if self.height < 0:
svg = self.document.getroot()
self.height = self.unittouu(svg.attrib['height'])
self.height = self.svg.unittouu(svg.attrib['height'])

line_style = { 'stroke-width':0.35433071, 'stroke':'#000000'}
line_style = { 'stroke-width':self.svg.unittouu(str(0.1)+"mm"), 'stroke':'#000000'}

line_attribs = {'style' : simplestyle.formatStyle(line_style),
'd' : 'M '+str(x1 * 3.5433071)+','+str(self.height - y1 * 3.5433071)+' L '+str(x2 * 3.5433071)+','+str(self.height - y2 * 3.5433071)}
line_attribs = {'style' : str(inkex.Style(line_style)),
'd' : 'M '+str(x1)+','+str(self.height - y1)+' L '+str(x2)+','+str(self.height - y2)}

line = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )


line = etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )

def effect(self):
width = self.options.width
height = self.options.height
Expand All @@ -47,26 +44,24 @@ def effect(self):
marks = self.options.addInitMarks == "true"
group = self.options.groupLines == "true"

parent = self.current_layer
parent = self.svg.get_current_layer()

if group:
parent = inkex.etree.SubElement(parent, 'g')
parent = etree.SubElement(parent, 'g')

xLines = int(width / horizontalLineSeparation)
maxLineLength = self.options.maxLineLength

linesPerColumn = int(math.ceil(height / maxLineLength))
ll = height / linesPerColumn



for x in range(0, xLines):
if marks:
self.draw_SVG_line((x * horizontalLineSeparation, -3), (x * horizontalLineSeparation, -2), parent)
self.draw_SVG_line(x * horizontalLineSeparation, -3, x * horizontalLineSeparation, -2, parent)

if x % 2 == 0:
for y in range(0, linesPerColumn):
self.draw_SVG_line((x * horizontalLineSeparation, y * ll + verticalLineSeparation / 2), (x * horizontalLineSeparation, (y + 1) * ll - verticalLineSeparation / 2), parent)
self.draw_SVG_line(x * horizontalLineSeparation, y * ll + verticalLineSeparation / 2, x * horizontalLineSeparation, (y + 1) * ll - verticalLineSeparation / 2, parent)

else:
for y in range(-1, linesPerColumn):
Expand All @@ -81,8 +76,6 @@ def effect(self):
if y1 > height:
y1 = height + 1

self.draw_SVG_line((x * horizontalLineSeparation, y0), (x * horizontalLineSeparation, y1), parent)
self.draw_SVG_line(x * horizontalLineSeparation, y0, x * horizontalLineSeparation, y1, parent)


effect = BendWoodCutsPattern()
effect.affect()
BendWoodCutsPattern().run()
79 changes: 33 additions & 46 deletions laserCut_LeatherCase1.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

#!/usr/bin/env python3
"""
A Inkscape extension to generate the pieces for a leather case that can be laser cut.

The leather case is intended to be used with up to 5 mobile phones.
"""

import sys, copy
import inkex, simpletransform
import simplestyle
import inkex
import math
from lxml import etree

class LeatherCase1(inkex.Effect):
height = -1.0

def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option('-w', '--width', action='store', type='float', dest='width', default=80, help='Width (mm)')
self.OptionParser.add_option('-x', '--height', action='store', type='float', dest='height', default=165, help='Height (mm)')
self.OptionParser.add_option('-d', '--depth', action='store', type='float', dest='depth', default=10, help='Depth (mm)')
self.OptionParser.add_option('-H', '--heightMargin', action='store', type='float', dest='heightMargin', default=10, help='Height Margin (mm)')
self.OptionParser.add_option('-r', '--cornerRoundness', action='store', type='float', dest='cornerRoundness', default=10, help='Corner Roundness (mm)')
self.OptionParser.add_option('-i', '--divisions', action='store', type='int', dest='divisions', default=2, help='Divisions')
self.OptionParser.add_option('-a', '--claspAmount', action='store', type='string', dest='claspAmount', default=1, help='Number of Clasps')
self.OptionParser.add_option('-p', '--extraTongueLength', action='store', type='float', dest='extraTongueLength', default=10, help='Extra Tongue Length (mm)')
self.OptionParser.add_option('-t', '--tipTongueLength', action='store', type='float', dest='tipTongueLength', default=40, help='Tip Tongue Length (mm)')
self.OptionParser.add_option('-e', '--extraEdgeWidth', action='store', type='float', dest='extraEdgeWidth', default=10, help='Extra Edge Width (mm)')
self.OptionParser.add_option('-o', '--makeHoles', action='store', type='string', dest='makeHoles', default="true", help='Make Holes')
self.OptionParser.add_option('-g', '--groupObjects', action='store', type='string', dest='groupObjects', default="false", help='Group Objects')
self.arg_parser.add_argument('-w', '--width', type=float, default=80, help='Width (mm)')
self.arg_parser.add_argument('-x', '--height', type=float, default=165, help='Height (mm)')
self.arg_parser.add_argument('-d', '--depth', type=float, default=10, help='Depth (mm)')
self.arg_parser.add_argument('-H', '--heightMargin', type=float, default=10, help='Height Margin (mm)')
self.arg_parser.add_argument('-r', '--cornerRoundness', type=float, default=10, help='Corner Roundness (mm)')
self.arg_parser.add_argument('-i', '--divisions', type=int, default=2, help='Divisions')
self.arg_parser.add_argument('-a', '--claspAmount', default=1, help='Number of Clasps')
self.arg_parser.add_argument('-p', '--extraTongueLength', type=float, default=10, help='Extra Tongue Length (mm)')
self.arg_parser.add_argument('-t', '--tipTongueLength', type=float,default=40, help='Tip Tongue Length (mm)')
self.arg_parser.add_argument('-e', '--extraEdgeWidth', type=float, default=10, help='Extra Edge Width (mm)')
self.arg_parser.add_argument('-o', '--makeHoles', default="true", help='Make Holes')
self.arg_parser.add_argument('-g', '--groupObjects', default="false", help='Group Objects')



def effect(self):
width = self.options.width
height = self.options.height
Expand All @@ -46,12 +41,12 @@ def effect(self):
makeHoles = self.options.makeHoles == "true"
group = self.options.groupObjects == "true"

parent = self.current_layer
parent = self.svg.get_current_layer()

if group:
parent = inkex.etree.SubElement(parent, 'g')
parent = etree.SubElement(parent, 'g')

line_style = { 'stroke-width': 3.5433071 / 15, 'stroke':'#FF0000', 'fill':'none'}
line_style = { 'stroke-width': self.svg.unittouu(str(0.1) + "mm"), 'stroke':'#FF0000', 'fill':'none'}

verticalLine1Size = width - cornerRoundness - 1

Expand All @@ -65,8 +60,7 @@ def effect(self):
' m 110,0' + ' c 1,0 2,1 2,2 0,1 -1,2 -2,2 -1,0 -2,-1 -2,-2 0,-1 1,-2 2,-2'
)

firstPiece_attribs = {'style' : simplestyle.formatStyle(line_style),
'transform' : 'matrix(3.5433071,0,0,3.5433071,0,0)',
firstPiece_attribs = {'style' : str(inkex.Style(line_style)),
'd' : 'M 0,0 l 0,' + str(verticalLine1Size) +
' c 0,' + str(cornerRoundness / 2.0) + ' ' + str(cornerRoundness / 2) + ',' + str(cornerRoundness) + ' ' + str(cornerRoundness) + ',' + str(cornerRoundness) +
' l ' + str(height + heightMargin * 2 - cornerRoundness * 2) + ',0' +
Expand All @@ -76,13 +70,12 @@ def effect(self):
}


firstPiece = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), firstPiece_attribs )
firstPiece = etree.SubElement(parent, inkex.addNS('path','svg'), firstPiece_attribs )


# Intermediate pieces
for x in range(1, divisions):
intermediatePiece_attribs = {'style' : simplestyle.formatStyle(line_style),
'transform' : 'matrix(3.5433071,0,0,3.5433071,0,0)',
intermediatePiece_attribs = {'style' : str(inkex.Style(line_style)),
'd' : 'M ' + str(10 + x*5) + ',' + str(10 + x*5) + ' l 0,' + str(verticalLine1Size) +
' c 0,' + str(cornerRoundness / 2.0) + ' ' + str(cornerRoundness / 2) + ',' + str(cornerRoundness) + ' ' + str(cornerRoundness) + ',' + str(cornerRoundness) +
' l ' + str(height + heightMargin * 2 - cornerRoundness * 2) + ',0' +
Expand All @@ -91,10 +84,10 @@ def effect(self):
}


intermediatePiece = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), intermediatePiece_attribs )
intermediatePiece = etree.SubElement(parent, inkex.addNS('path','svg'), intermediatePiece_attribs )


line_style2 = { 'stroke-width': 3.5433071 / 15, 'stroke':'#00FF00', 'fill':'none'}
line_style2 = { 'stroke-width': self.svg.unittouu(str(0.1) + "mm"), 'stroke':'#00FF00', 'fill':'none'}
plainTongueLength = depth * divisions + extraTongueLength - 1 + (divisions - 1)
totalWidth = height + heightMargin * 2;
hole = ''
Expand All @@ -121,8 +114,7 @@ def effect(self):
' l 0,' + str(plainTongueLength + tipTongueLength - cornerRoundness)
)

secondPiece_attribs = {'style' : simplestyle.formatStyle(line_style2),
'transform' : 'matrix(3.5433071,0,0,3.5433071,0,0)',
secondPiece_attribs = {'style' : str(inkex.Style(line_style2)),
'd' : 'M -5,-4 l 0,' + str(verticalLine1Size - 1) +
' c 0,' + str(cornerRoundness / 2.0) + ' ' + str(cornerRoundness / 2) + ',' + str(cornerRoundness) + ' ' + str(cornerRoundness) + ',' + str(cornerRoundness) +
' l ' + str(height + heightMargin * 2 - cornerRoundness * 2) + ',0' +
Expand All @@ -138,35 +130,30 @@ def effect(self):
hole
}

secondPiece = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), secondPiece_attribs )
secondPiece = etree.SubElement(parent, inkex.addNS('path','svg'), secondPiece_attribs )

line_style3 = { 'stroke-width': 3.5433071 / 15, 'stroke':'#0000FF', 'fill':'none'}
line_style3 = { 'stroke-width': self.svg.unittouu(str(0.1) + "mm"), 'stroke':'#0000FF', 'fill':'none'}
edgeLength = (width - cornerRoundness) * 2 + height + heightMargin * 2 - cornerRoundness * 2 + 3.14159 * cornerRoundness
edgeWidth = depth * divisions + divisions - 1 + extraEdgeWidth

thirdPiece_attribs = {'style' : simplestyle.formatStyle(line_style3),
'transform' : 'matrix(3.5433071,0,0,3.5433071,0,0)',
thirdPiece_attribs = {'style' : str(inkex.Style(line_style3)),
'd' : 'M 5,5 l 0,' + str(edgeWidth) +
' ' + str(edgeLength) + ',0' +
' 0,' + str(-edgeWidth) + ' Z'
}

thirdPiece = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), thirdPiece_attribs )
thirdPiece = etree.SubElement(parent, inkex.addNS('path','svg'), thirdPiece_attribs )

line_style4 = { 'stroke-width': 3.5433071 / 15, 'stroke':'#FF00FF', 'fill':'none'}
line_style4 = { 'stroke-width': self.svg.unittouu(str(0.1) + "mm"), 'stroke':'#FF00FF', 'fill':'none'}
edgeLength = 70
edgeWidth = 60

fourthPiece_attribs = {'style' : simplestyle.formatStyle(line_style4),
'transform' : 'matrix(3.5433071,0,0,3.5433071,0,0)',
fourthPiece_attribs = {'style' : str(inkex.Style(line_style4)),
'd' : 'M 10,10 l 0,' + str(edgeWidth) +
' ' + str(edgeLength) + ',0' +
' 0,' + str(-edgeWidth) + ' Z'
}

fourthPiece = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), fourthPiece_attribs )



effect = LeatherCase1()
effect.affect()
fourthPiece = etree.SubElement(parent, inkex.addNS('path','svg'), fourthPiece_attribs )

LeatherCase1().run()