├── .gitignore
├── LICENSE
├── Lasercut_box.inx
├── Lasercut_box.py
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 |
3 | # C extensions
4 | *.so
5 |
6 | # Packages
7 | *.egg
8 | *.egg-info
9 | dist
10 | build
11 | eggs
12 | parts
13 | bin
14 | var
15 | sdist
16 | develop-eggs
17 | .installed.cfg
18 | lib
19 | lib64
20 | __pycache__
21 |
22 | # Installer logs
23 | pip-log.txt
24 |
25 | # Unit test / coverage reports
26 | .coverage
27 | .tox
28 | nosetests.xml
29 |
30 | # Translations
31 | *.mo
32 |
33 | # Mr Developer
34 | .mr.developer.cfg
35 | .project
36 | .pydevproject
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/Lasercut_box.inx:
--------------------------------------------------------------------------------
1 |
2 |
3 | Lasercut Box
4 | org.inkscape.LasercutBox
5 | Lasercut_box.py
6 |
7 |
8 | Dimensions can measure the external or internal size of the box.
9 | The corner cubes can be omitted.
10 | The document units should be set to mm instead of pixels (assuming you mean to really cut it out with a laser).
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | 50.0
22 | 30.0
23 | 15
24 | 3.0
25 | 11
26 | 11
27 | 6
28 | true
29 | true
30 |
31 |
32 | The kerf is the amount lost to the burning width of the laser.
33 | Typically in the range 0.1 to 0.4 mm. Check with your laser vendor. This will depend on the material being cut and the speed of the laser.
34 |
35 | Setting the kerf to 0 will create a box that will use the least material. However the material lost to the laser will make for a loose fit and probably require glue.
36 |
37 | If the Kerf is greater than zero then you can have a calculated "Precise fit" or add dimples for a "Press fit".
38 | A "Precise fit" will change the width of the tabs to allow for the material burned away by the laser and make a tight fit.
39 | Dimples will add notches for a "Press fit" (see next tab)
40 |
41 | The pattern will be spread out, using more material, because a common laser cut line cannot be used.
42 |
43 |
44 |
45 |
46 | 0.0
47 | false
48 |
49 |
50 | Dimples are used so that a press-fit can be
51 | made in deformable materials like wood.
52 |
53 | If Dimple is checked then no "precise fit" kerf adjustment is made to the tabs. Instead a small dimple is added to each notch to enable a press fit.
54 | - the dimple size is equal to the kerf size.
55 |
56 | Dimples are useful for flexible materials like wood but are not good for rigid materials like perspex.
57 |
58 | Dimple style is half rounds or triangles. Triangles are cheaper to cut, Half rounds fit better.
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | false
68 |
69 |
70 |
71 |
72 |
73 | Colours:
74 | The color scheme used by Ponoko is used here:
75 | Specifically:
76 | - Blue (0,0,255) is the lasercut line color
77 | - Orange is a non-printing annotation
78 | The lines are all 0.1mm in width - as required by Ponoko.
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | all
95 |
96 |
97 |
98 |
99 |
102 |
103 |
--------------------------------------------------------------------------------
/Lasercut_box.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env/python
2 | '''
3 | Copyright (C)2011 Mark Schafer
4 |
5 | This program is free software; you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation; either version 2 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program; if not, write to the Free Software
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 | '''
18 |
19 | # Build a tabbed box for lasercutting with tight fit, and minimal material use options.
20 | # User defines:
21 | # - internal or external dimensions,
22 | # - number of tabs,
23 | # - amount lost to laser (kerf),
24 | # - include corner cubes or not,
25 | # - dimples, or perfect fit (accounting for kerf).
26 | # If zero kerf - will be perfectly packed for minimal laser cuts and material size.
27 |
28 | ### Todo
29 | # add option to pack multiple boxes (if zero kerf) - new tab maybe?
30 | # add option for little circles at sharp corners for acrylic
31 | # annotations: - add overlap value as markup - Ponoko annotation color
32 | # choose colours from a dictionary
33 |
34 | ### Versions
35 | # 0.1 February 2011 - basic lasercut box with dimples etc
36 | # 0.2 changes to unittouu for Inkscape 0.91
37 | # 0.3 Option to avoid half-sized tabs at corners.
38 |
39 | __version__ = "0.3"
40 |
41 | #from math import *
42 | import sys
43 | import inkex
44 | from simplepath import *
45 | from lxml import etree
46 |
47 |
48 | class LasercutBox(inkex.Effect):
49 |
50 | def __init__(self):
51 | inkex.Effect.__init__(self)
52 | self.arg_parser.add_argument("-i", "--int_ext",
53 | type=inkex.Boolean,
54 | dest="int_ext", default=False,
55 | help="Are the Dimensions for External or Internal sizing.")
56 | self.arg_parser.add_argument("-x", "--width",
57 | type=float,
58 | dest="width", default=50.0,
59 | help="The Box Width - in the X dimension")
60 | self.arg_parser.add_argument("-y", "--height",
61 | type=float,
62 | dest="height", default=30.0,
63 | help="The Box Height - in the Y dimension")
64 | self.arg_parser.add_argument("-z", "--depth",
65 | type=float,
66 | dest="depth", default=15.0,
67 | help="The Box Depth - in the Z dimension")
68 | self.arg_parser.add_argument("-t", "--thickness",
69 | type=float,
70 | dest="thickness", default=3.0,
71 | help="Material Thickness - critical to know")
72 | self.arg_parser.add_argument("-u", "--units",
73 | type=str,
74 | dest="units", default="cm",
75 | help="The unit of the box dimensions")
76 | self.arg_parser.add_argument("-c", "--corners",
77 | type=inkex.Boolean,
78 | dest="corners", default=True,
79 | help="The corner cubes can be removed for a different look")
80 | self.arg_parser.add_argument("-H", "--halftabs",
81 | type=inkex.Boolean,
82 | dest="halftabs", default=True,
83 | help="Start/End with half-sized tabs - Avoid with very small tabs")
84 | self.arg_parser.add_argument("-p", "--ntab_W",
85 | type=int,
86 | dest="ntab_W", default=11,
87 | help="Number of tabs in Width")
88 | self.arg_parser.add_argument("-q", "--ntab_H",
89 | type=int,
90 | dest="ntab_H", default=11,
91 | help="Number of tabs in Height")
92 | self.arg_parser.add_argument("-r", "--ntab_D",
93 | type=int,
94 | dest="ntab_D", default=6,
95 | help="Number of tabs in Depth")
96 | self.arg_parser.add_argument("-k", "--kerf_size",
97 | type=float,
98 | dest="kerf_size", default=0.0,
99 | help="Kerf size - amount lost to laser for this material. 0 = loose fit")
100 | self.arg_parser.add_argument("-d", "--dimples",
101 | type=inkex.Boolean,
102 | dest="dimples", default=False,
103 | help="Add dimples for press fitting wooden materials")
104 | self.arg_parser.add_argument("-s", "--dstyle",
105 | type=inkex.Boolean,
106 | dest="dstyle", default=False,
107 | help="Dimples can be triangles(cheaper) or half rounds(better)")
108 | self.arg_parser.add_argument("-g", "--linewidth",
109 | type=inkex.Boolean,
110 | dest="linewidth", default=False,
111 | help="Use the kerf value as the drawn line width")
112 | # self.arg_parser.add_argument("-j", "--annotation",
113 | # type=inkex.Boolean,
114 | # dest="annotation", default=True,
115 | # help="Show Kerf value as annotation")
116 | #dummy for the doc tab - which is named
117 | self.arg_parser.add_argument("--tab",
118 | type=str,
119 | dest="tab", default="use",
120 | help="The selected UI-tab when OK was pressed")
121 | #internal useful variables
122 | self.stroke_width = 0.1 #default for visiblity
123 | self.line_style = {'stroke': '#0000FF', # Ponoko blue
124 | 'fill': 'none',
125 | 'stroke-width': self.stroke_width,
126 | 'stroke-linecap': 'butt',
127 | 'stroke-linejoin': 'miter'}
128 |
129 | def annotation(self, x, y, text):
130 | """ Draw text at this location
131 | - change to path
132 | - use annotation color """
133 | pass
134 |
135 |
136 | def thickness_line(self, dimple, vert_horiz, pos_neg):
137 | """ called to draw dimples (also draws simple lines if no dimple)
138 | - pos_neg is 1, -1 for direction
139 | - vert_horiz is v or h """
140 | if dimple and self.kerf > 0.0: # we need a dimple
141 | # size is radius = kerf
142 | # short line, half circle, short line
143 | #[ 'C', [x1,y1, x2,y2, x,y] ] x1 is first handle, x2 is second
144 | lines = []
145 | radius = self.kerf
146 | if self.thick - 2 * radius < 0.2: # correct for large dimples(kerf) on small thicknesses
147 | radius = (self.thick - 0.2) / 2
148 | short = 0.1
149 | else:
150 | short = self.thick/2 - radius
151 | if vert_horiz == 'v': # vertical line
152 | # first short line
153 | lines.append(['v', [pos_neg*short]])
154 | # half circle
155 | if pos_neg == 1: # only the DH_sides need reversed tabs to interlock
156 | if self.dimple_tri:
157 | lines.append(['l', [radius, pos_neg*radius]])
158 | lines.append(['l', [-radius, pos_neg*radius]])
159 | else:
160 | lines.append(['c', [radius, 0, radius, pos_neg*2*radius, 0, pos_neg*2*radius]])
161 | else:
162 | if self.dimple_tri:
163 | lines.append(['l', [-radius, pos_neg*radius]])
164 | lines.append(['l', [radius, pos_neg*radius]])
165 | else:
166 | lines.append(['c', [-radius, 0, -radius, pos_neg*2*radius, 0, pos_neg*2*radius]])
167 | # last short line
168 | lines.append(['v', [pos_neg*short]])
169 | else: # horizontal line
170 | # first short line
171 | lines.append(['h', [pos_neg*short]])
172 | # half circle
173 | if self.dimple_tri:
174 | lines.append(['l', [pos_neg*radius, radius]])
175 | lines.append(['l', [pos_neg*radius, -radius]])
176 | else:
177 | lines.append(['c', [0, radius, pos_neg*2*radius, radius, pos_neg*2*radius, 0]])
178 | # last short line
179 | lines.append(['h', [pos_neg*short]])
180 | return lines
181 |
182 | # No dimple - so much easier
183 | else: # return a straight v or h line same as thickness
184 | if vert_horiz == 'v':
185 | return [ ['v', [pos_neg*self.thick]] ]
186 | else:
187 | return [ ['h', [pos_neg*self.thick]] ]
188 |
189 |
190 | def draw_WH_lid(self, startx, starty, masktop=False):
191 | """ Return an SVG path for the top or bottom of box
192 | - the Width * Height dimension """
193 | line_path = []
194 | line_path.append(['M', [startx, starty]])
195 | # top row of tabs
196 | if masktop and self.kerf ==0.0: # don't draw top for packing with no extra cuts
197 | line_path.append(['m', [self.boxW, 0]])
198 | else:
199 | if not self.ht: line_path.append(['l', [self.boxW/self.Wtabs/4 - self.pf/2, 0]])
200 | for i in range(int(self.Wtabs)):
201 | line_path.append(['h', [self.boxW/self.Wtabs/4 - self.pf/2]])
202 | #line_path.append(['v', [0, -thick]]) # replaced with dimpled version
203 | for l in self.thickness_line(self.dimple, 'v', -1):
204 | line_path.append(l)
205 | line_path.append(['h', [self.boxW/self.Wtabs/2 + self.pf]])
206 | line_path.append(['v', [self.thick]])
207 | line_path.append(['h', [self.boxW/self.Wtabs/4 - self.pf/2]])
208 | if not self.ht: line_path.append(['l', [self.boxW/self.Wtabs/4 - self.pf/2, 0]])
209 | # right hand vertical drop
210 | if not self.ht: line_path.append(['l', [0, self.boxH/self.Htabs/4 - self.pf/2]])
211 | for i in range(int(self.Htabs)):
212 | line_path.append(['v', [self.boxH/self.Htabs/4 - self.pf/2]])
213 | line_path.append(['h', [self.thick]])
214 | line_path.append(['v', [self.boxH/self.Htabs/2 + self.pf]])
215 | #line_path.append(['h', [-thick]]) # replaced with dimpled version
216 | for l in self.thickness_line(self.dimple, 'h', -1):
217 | line_path.append(l)
218 | line_path.append(['v', [self.boxH/self.Htabs/4 - self.pf/2]])
219 | if not self.ht: line_path.append(['l', [0, self.boxH/self.Htabs/4 - self.pf/2]])
220 | # bottom row (in reverse)
221 | if not self.ht: line_path.append(['l', [-self.boxW/self.Wtabs/4 + self.pf/2, 0]])
222 | for i in range(int(self.Wtabs)):
223 | line_path.append(['h', [-self.boxW/self.Wtabs/4 + self.pf/2]])
224 | line_path.append(['v', [self.thick]])
225 | line_path.append(['h', [-self.boxW/self.Wtabs/2 - self.pf]])
226 | #line_path.append(['v', [0, -thick]]) # replaced with dimpled version
227 | for l in self.thickness_line(self.dimple, 'v', -1):
228 | line_path.append(l)
229 | line_path.append(['h', [-self.boxW/self.Wtabs/4 + self.pf/2]])
230 | if not self.ht: line_path.append(['l', [-self.boxW/self.Wtabs/4 + self.pf/2, 0]])
231 | # up the left hand side
232 | if not self.ht: line_path.append(['l', [0, -self.boxH/self.Htabs/4 + self.pf/2]])
233 | for i in range(int(self.Htabs)):
234 | line_path.append(['v', [-self.boxH/self.Htabs/4 + self.pf/2]])
235 | #line_path.append(['h', [-thick]]) # replaced with dimpled version
236 | for l in self.thickness_line(self.dimple, 'h', -1):
237 | line_path.append(l)
238 | line_path.append(['v', [-self.boxH/self.Htabs/2 - self.pf]])
239 | line_path.append(['h', [self.thick]])
240 | line_path.append(['v', [-self.boxH/self.Htabs/4 + self.pf/2]])
241 | if not self.ht: line_path.append(['l', [0, -self.boxH/self.Htabs/4 + self.pf/2]])
242 | return line_path
243 |
244 |
245 | def draw_WD_side(self, startx, starty, mask=False, corners=True):
246 | """ Return an SVG path for the long side of box
247 | - the Width * Depth dimension """
248 | # Draw side of the box (placed below the lid)
249 | line_path = []
250 | # top row of tabs
251 | if corners:
252 | line_path.append(['M', [startx - self.thick, starty]])
253 | line_path.append(['v', [-self.thick]])
254 | line_path.append(['h', [self.thick]])
255 | else:
256 | line_path.append(['M', [startx, starty]])
257 | line_path.append(['v', [-self.thick]])
258 | #
259 | if self.kerf > 0.0: # if fit perfectly - don't draw double line
260 | if not self.ht: line_path.append(['l', [self.boxW/self.Wtabs/4 + self.pf/2, 0]])
261 | for i in range(int(self.Wtabs)):
262 | line_path.append(['h', [self.boxW/self.Wtabs/4 + self.pf/2]])
263 | line_path.append(['v', [self.thick]])
264 | line_path.append(['h', [self.boxW/self.Wtabs/2 - self.pf]])
265 | #line_path.append(['v', [0, -thick]]) # replaced with dimpled version
266 | for l in self.thickness_line(self.dimple, 'v', -1):
267 | line_path.append(l)
268 | line_path.append(['h', [self.boxW/self.Wtabs/4 + self.pf/2]])
269 | if not self.ht: line_path.append(['l', [self.boxW/self.Wtabs/4 + self.pf/2, 0]])
270 | if corners: line_path.append(['h', [self.thick]])
271 | else: # move to skipped drawn lines
272 | if corners:
273 | line_path.append(['m', [self.boxW + self.thick, 0]])
274 | else:
275 | line_path.append(['m', [self.boxW, 0]])
276 | #
277 | line_path.append(['v', [self.thick]])
278 | if not corners: line_path.append(['h', [self.thick]])
279 | # RHS
280 | if not self.ht: line_path.append(['l', [0, self.boxD/self.Dtabs/4 + self.pf/2]])
281 | for i in range(int(self.Dtabs)):
282 | line_path.append(['v', [self.boxD/self.Dtabs/4 + self.pf/2]])
283 | #line_path.append(['h', [-thick]]) # replaced with dimpled version
284 | for l in self.thickness_line(self.dimple, 'h', -1):
285 | line_path.append(l)
286 | line_path.append(['v', [self.boxD/self.Dtabs/2 - self.pf]])
287 | line_path.append(['h', [self.thick]])
288 | line_path.append(['v', [self.boxD/self.Dtabs/4 + self.pf/2]])
289 | if not self.ht: line_path.append(['l', [0, self.boxD/self.Dtabs/4 + self.pf/2]])
290 | #
291 | if corners:
292 | line_path.append(['v', [self.thick]])
293 | line_path.append(['h', [-self.thick]])
294 | else:
295 | line_path.append(['h', [-self.thick]])
296 | line_path.append(['v', [self.thick]])
297 | # base
298 | if not self.ht: line_path.append(['l', [-self.boxW/self.Wtabs/4 - self.pf/2, 0]])
299 | for i in range(int(self.Wtabs)):
300 | line_path.append(['h', [-self.boxW/self.Wtabs/4 - self.pf/2]])
301 | #line_path.append(['v', [0, -thick]]) # replaced with dimpled version
302 | for l in self.thickness_line(self.dimple, 'v', -1):
303 | line_path.append(l)
304 | line_path.append(['h', [-self.boxW/self.Wtabs/2 + self.pf]])
305 | line_path.append(['v', [self.thick]])
306 | line_path.append(['h', [-self.boxW/self.Wtabs/4 - self.pf/2]])
307 | if not self.ht: line_path.append(['l', [-self.boxW/self.Wtabs/4 - self.pf/2, 0]])
308 | #
309 | if corners:
310 | line_path.append(['h', [-self.thick]])
311 | line_path.append(['v', [-self.thick]])
312 | else:
313 | line_path.append(['v', [-self.thick]])
314 | line_path.append(['h', [-self.thick]])
315 | # LHS
316 | if not self.ht: line_path.append(['l', [0, -self.boxD/self.Dtabs/4 - self.pf/2]])
317 | for i in range(int(self.Dtabs)):
318 | line_path.append(['v', [-self.boxD/self.Dtabs/4 - self.pf/2]])
319 | line_path.append(['h', [self.thick]])
320 | line_path.append(['v', [-self.boxD/self.Dtabs/2 + self.pf]])
321 | #line_path.append(['h', [-thick]]) # replaced with dimpled version
322 | for l in self.thickness_line(self.dimple, 'h', -1):
323 | line_path.append(l)
324 | line_path.append(['v', [-self.boxD/self.Dtabs/4 - self.pf/2]])
325 | if not self.ht: line_path.append(['l', [0, -self.boxD/self.Dtabs/4 - self.pf/2]])
326 | #
327 | if not corners: line_path.append(['h', [self.thick]])
328 | return line_path
329 |
330 |
331 | def draw_HD_side(self, startx, starty, corners, mask=False):
332 | """ Return an SVG path for the short side of box
333 | - the Height * Depth dimension """
334 | line_path = []
335 | # top row of tabs
336 | line_path.append(['M', [startx, starty]])
337 | if not(mask and corners and self.kerf == 0.0):
338 | line_path.append(['h', [self.thick]])
339 | else:
340 | line_path.append(['m', [self.thick, 0]])
341 | if not self.ht: line_path.append(['l', [self.boxD/self.Dtabs/4 - self.pf/2, 0]])
342 | for i in range(int(self.Dtabs)):
343 | line_path.append(['h', [self.boxD/self.Dtabs/4 - self.pf/2]])
344 | line_path.append(['v', [-self.thick]])
345 | line_path.append(['h', [self.boxD/self.Dtabs/2 + self.pf]])
346 | #line_path.append(['v', [0, thick]]) # replaced with dimpled version
347 | for l in self.thickness_line(self.dimple, 'v', 1):
348 | line_path.append(l)
349 | line_path.append(['h', [self.boxD/self.Dtabs/4 - self.pf/2]])
350 | if not self.ht: line_path.append(['l', [self.boxD/self.Dtabs/4 - self.pf/2, 0]])
351 | line_path.append(['h', [self.thick]])
352 | #
353 | if not self.ht: line_path.append(['l', [0, self.boxH/self.Htabs/4 + self.pf/2]])
354 | for i in range(int(self.Htabs)):
355 | line_path.append(['v', [self.boxH/self.Htabs/4 + self.pf/2]])
356 | #line_path.append(['h', [-thick]]) # replaced with dimpled version
357 | for l in self.thickness_line(self.dimple, 'h', -1):
358 | line_path.append(l)
359 | line_path.append(['v', [self.boxH/self.Htabs/2 - self.pf]])
360 | line_path.append(['h', [self.thick]])
361 | line_path.append(['v', [self.boxH/self.Htabs/4 + self.pf/2]])
362 | if not self.ht: line_path.append(['l', [0, self.boxH/self.Htabs/4 + self.pf/2]])
363 | line_path.append(['h', [-self.thick]])
364 | #
365 | if not self.ht: line_path.append(['l', [-self.boxD/self.Dtabs/4 + self.pf/2, 0]])
366 | for i in range(int(self.Dtabs)):
367 | line_path.append(['h', [-self.boxD/self.Dtabs/4 + self.pf/2]])
368 | #line_path.append(['v', [0, thick]]) # replaced with dimpled version
369 | for l in self.thickness_line(self.dimple, 'v', 1): # this is the weird +1 instead of -1 dimple
370 | line_path.append(l)
371 | line_path.append(['h', [-self.boxD/self.Dtabs/2 - self.pf]])
372 | line_path.append(['v', [-self.thick]])
373 | line_path.append(['h', [-self.boxD/self.Dtabs/4 + self.pf/2]])
374 | if not self.ht: line_path.append(['l', [-self.boxD/self.Dtabs/4 + self.pf/2, 0]])
375 | line_path.append(['h', [-self.thick]])
376 | #
377 | if self.kerf > 0.0: # if fit perfectly - don't draw double line
378 | if not self.ht: line_path.append(['l', [0, -self.boxH/self.Htabs/4 - self.pf/2]])
379 | for i in range(int(self.Htabs)):
380 | line_path.append(['v', [-self.boxH/self.Htabs/4 - self.pf/2]])
381 | line_path.append(['h', [self.thick]])
382 | line_path.append(['v', [-self.boxH/self.Htabs/2 + self.pf]])
383 | #line_path.append(['h', [-thick, 0]]) # replaced with dimpled version
384 | for l in self.thickness_line(self.dimple, 'h', -1):
385 | line_path.append(l)
386 | line_path.append(['v', [-self.boxH/self.Htabs/4 - self.pf/2]])
387 | if not self.ht: line_path.append(['l', [0, -self.boxH/self.Htabs/4 - self.pf/2]])
388 | return line_path
389 |
390 |
391 |
392 | ###--------------------------------------------
393 | ### The main function called by the inkscape UI
394 | def effect(self):
395 | # document dimensions (for centering)
396 | docW = self.svg.unittouu(self.document.getroot().get('width'))
397 | docH = self.svg.unittouu(self.document.getroot().get('height'))
398 | # extract fields from UI
399 | self.boxW = self.svg.unittouu(str(self.options.width) + self.options.units)
400 | self.boxH = self.svg.unittouu(str(self.options.height) + self.options.units)
401 | self.boxD = self.svg.unittouu(str(self.options.depth) + self.options.units)
402 | self.thick = self.svg.unittouu(str(self.options.thickness) + self.options.units)
403 | self.kerf = self.svg.unittouu(str(self.options.kerf_size) + self.options.units)
404 | if self.kerf < 0.01: self.kerf = 0.0 # snap to 0 for UI error when setting spinner to 0.0
405 | self.Wtabs = self.options.ntab_W
406 | self.Htabs = self.options.ntab_H
407 | self.Dtabs = self.options.ntab_D
408 | self.dimple = self.options.dimples
409 | line_width = self.options.linewidth
410 | corners = self.options.corners
411 | self.dimple_tri = self.options.dstyle
412 | # self.annotation = self.options.annotation
413 | self.ht = self.options.halftabs
414 | if not self.ht:
415 | self.Wtabs += 0.5
416 | self.Htabs += 0.5
417 | self.Dtabs += 0.5
418 |
419 | # Correct for thickness in dimensions
420 | if self.options.int_ext: # external so add thickness
421 | self.boxW -= self.thick*2
422 | self.boxH -= self.thick*2
423 | self.boxD -= self.thick*2
424 | # adjust for laser kerf (precise measurement)
425 | self.boxW += self.kerf
426 | self.boxH += self.kerf
427 | self.boxD += self.kerf
428 |
429 | # Precise fit or dimples (if kerf > 0.0)
430 | if self.dimple == False: # and kerf > 0.0:
431 | self.pf = self.kerf
432 | else:
433 | self.pf = 0.0
434 |
435 | # set the stroke width and line style
436 | sw = self.kerf
437 | if self.kerf == 0.0: sw = self.stroke_width
438 | ls = self.line_style
439 | if line_width: # user wants drawn line width to be same as kerf size
440 | ls['stroke-width'] = sw
441 | line_style = str(inkex.Style(ls))
442 |
443 | ###---------------------------
444 | ### create the inkscape object
445 | box_id = self.svg.get_unique_id('box')
446 | self.box = g = etree.SubElement(self.svg.get_current_layer(), 'g', {'id':box_id})
447 |
448 | #Set local position for drawing (will transform to center of doc at end)
449 | lower_pos = 0
450 | left_pos = 0
451 | # Draw Lid (using SVG path definitions)
452 | line_path = self.draw_WH_lid(left_pos, lower_pos)
453 | #print(str(line_path), file=sys.stderr)
454 | # Add to scene
455 | line_atts = { 'style':line_style, 'id':box_id+'-lid', 'd':str(Path(line_path)) }
456 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
457 |
458 | # draw the side of the box directly below
459 | if self.kerf > 0.0:
460 | lower_pos += self.boxH + (3*self.thick)
461 | else: # kerf = 0 so don't draw extra lines and fit perfectly
462 | lower_pos += self.boxH + self.thick # at lower edge of lid
463 | left_pos += 0
464 | # Draw side of the box (placed below the lid)
465 | line_path = self.draw_WD_side(left_pos, lower_pos, corners=corners)
466 | # Add to scene
467 | line_atts = { 'style':line_style, 'id':box_id+'-longside1', 'd':str(Path(line_path)) }
468 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
469 |
470 | # draw the bottom of the box directly below
471 | if self.kerf > 0.0:
472 | lower_pos += self.boxD + (3*self.thick)
473 | else: # kerf = 0 so don't draw extra lines and fit perfectly
474 | lower_pos += self.boxD + self.thick # at lower edge
475 | left_pos += 0
476 | # Draw base of the box
477 | line_path = self.draw_WH_lid(left_pos, lower_pos, True)
478 | # Add to scene
479 | line_atts = { 'style':line_style, 'id':box_id+'-base', 'd':str(Path(line_path)) }
480 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
481 |
482 | # draw the second side of the box directly below
483 | if self.kerf > 0.0:
484 | lower_pos += self.boxH + (3*self.thick)
485 | else: # kerf = 0 so don't draw extra lines and fit perfectly
486 | lower_pos += self.boxH + self.thick # at lower edge of lid
487 | left_pos += 0
488 | # Draw side of the box (placed below the lid)
489 | line_path = self.draw_WD_side(left_pos, lower_pos, corners=corners)
490 | # Add to scene
491 | line_atts = { 'style':line_style, 'id':box_id+'-longside2', 'd':str(Path(line_path)) }
492 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
493 |
494 | # draw next on RHS of lid
495 | if self.kerf > 0.0:
496 | left_pos += self.boxW + (2*self.thick) # adequate space (could be a param for separation when kerf > 0)
497 | else:
498 | left_pos += self.boxW # right at right edge of lid
499 | lower_pos = 0
500 | # Side of the box (placed next to the lid)
501 | line_path = self.draw_HD_side(left_pos, lower_pos, corners)
502 | # Add to scene
503 | line_atts = { 'style':line_style, 'id':box_id+'-endface2', 'd':str(Path(line_path)) }
504 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
505 |
506 | # draw next on RHS of base
507 | if self.kerf > 0.0:
508 | lower_pos += self.boxH + self.boxD + 6*self.thick
509 | else:
510 | lower_pos += self.boxH +self.boxD + 2*self.thick
511 | # Side of the box (placed next to the lid)
512 | line_path = self.draw_HD_side(left_pos, lower_pos, corners, True)
513 | # Add to scene
514 | line_atts = { 'style':line_style, 'id':box_id+'-endface1', 'd':str(Path(line_path)) }
515 | etree.SubElement(g, inkex.addNS('path','svg'), line_atts)
516 |
517 |
518 | ###----------------------------------------
519 | # Transform entire drawing to center of doc
520 | lower_pos += self.boxH*2 + self.boxD*2 + 2*self.thick
521 | left_pos += self.boxH + 2*self.thick
522 | g.set( 'transform', 'translate(%f,%f)' % ( (docW-left_pos)/2, (docH-lower_pos)/2))
523 |
524 |
525 | ###
526 | if __name__ == '__main__':
527 | e = LasercutBox()
528 | e.run()
529 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Inkscape-LasercutBox
2 | ====================
3 |
4 | Creates a tabbed box with kerf setting for tight fits. Or dimples for press fits.
5 | * set dimensions in various units,
6 | * width, depth, height, material thickness,
7 | * choose number of tabs for each dimension,
8 | * include corners or not,
9 | * kerf adjustable - if tight fit required, or
10 | * can use dimples for pressure fits for wood etc (rounds or triangles), or
11 | * can set zero kerf and use minimal material to create.
12 |
13 | In all cases - uses minimal lines to optimise for laser cutting.
14 |
15 |
16 | Install:
17 | - windows: drop inx and py files into folder %appdata%/inkscape/extensions
18 |
--------------------------------------------------------------------------------