jack000 / svgnest Goto Github PK
View Code? Open in Web Editor NEWAn open source vector nesting tool
License: MIT License
An open source vector nesting tool
License: MIT License
Hey,
I've been testing your software and it's amazing. Congratulations!
I have a question regarding de base/bin where the other elements are placed. Is there any way to add a polygon which has to be fixed and not traslated/rotated by the algorithm and will have no pieces inside it placed once the algoritm finishes?
I mean for example a base which is some kind of material which has stains and we dont want to place pieces onto.
I've been thinking if i can nest a svg inside the svg where all the other pieces are and mark it as the bin. Would it be possible?
Thank you very much in advice!
After nesting few elements (files attached) 2 shapes "S" and "W" letter was slightly different from original.
Why this happened?
The second thing is, space in svgnest configuration was set to 10 (or 12 don't remember) - svg was was set to mm in inkscape. And after nesting the space is around 3,5mm.
As I see this nesting program is able to nest only imported geometry as SVG shapes.
It will be very useful to be able to nest geometry from CSV files where the elements are defined as dimension values, like in the bellow example:
500, 200, 5
230, 120, 3
120, 320, 2
Where the first column is always the grain orientation, and the last one is the quantity of parts/shape to be nested.
Great work !.
I suggest an optimisation which could be added as an option.
If two edges are coincident and one lies enirely within the length of the other, then eliminate the shorter edge.
This will optimise out the duplication of cuts in a way that does not chop an edge into a number of shorter cuts - which frequently generates bumps in a physically cut result. Further types of reuction could be looked at as well but the direction and order of each cut is an ordering problem within the SVG and a tricky one to calculate.
What do I do about this?
Hi Jack
First of all i thank you for the wonderful project. Being in material optimization job, I know how difficult to work with nesting. This SVGnest does impressive job.
I request you to consider this enhancement in higher priority - "Skipping the nesting in the defect regions of sheet/bin". It is a must need feature when you think about automated nesting coz not every sheet/bin will be a defect free solids.
I guess as discussed in an another thread, "Treat pieces inside the bin as locked" will be a better solution.
Attached samples for your reference
Thanks
Nadum Sing
How can we use mm / cm measures for the bin and the objects which are nested and prevent any resizing and zooming?
Hi, I try to load SVGNest in a QWebView and have an issue :
TypeError: undefined is not an object (evaluating 'element.getAttribute')
Have you any solution ?
Thanks.
I was trying to use this to process some Ponoko files, which have colored strokes and fills to represent etched/cut line intensities and etched area intensities respectively. Unfortunately, SVGNest removes fill and stroke colors after processing.
I also had some issues with Deepnest.io, but both tools seem great; just not for my use case.
i set Part rotations=0 but parts rotate the same
is there anyway to specified ordering?
for example nesting order from left to right or from bottom to top.
Hi.
Can you please guide me how to start SVGnest?
I'm getting some weird results when trying to run this to create some multi-page layouts.
ive attached an example input/output.
Hi.
I am trying to load shapes generated with Kabeja. Unfortunately many of them does not appear correct. If I first simplify in Inkscape it works. However simplify is not good, further Id like if it could load for nest directly.
I have attached a few simple examples og SVG. the rendering problem has nothing to do with SVGNEST.
Hi,
What if I have more pieces that I can fit onto one sheet? Could it place the pieces onto multiple sheets?
When I upload the SVG file and run the script the programme only recognises 107 out of 139 elements. I'm running the script with the standard settings apart from a 20mm gap between pieces. Any ideas?
Example.zip
Interesting stuff this SVGnest.
I also commented in #15. That was about grain-direction in wood. I repeat my comments here:
In metal sheet industry the requirements are somewhat more complex compared to the wood-grain issue.
Metal sheet proces is as follows: Sheet metal is cut (lasered or punched) Next step is bending on a press brake. For the press-brake it is important that the grain (molecular structure) is in the same direction for all identical parts in the nest. That is a prerequisition to have a consistent bend during the complete batch. In most cases it does not matter if grain is along or perpendicular to bending axis.
Now back to nesting and rotations: Commercial nesting software often has an option to select allowable rotations of a part. Most of the time this is set per part to (0 or 180) or to (90 or 270). This will ensure grain directions for identical parts to be the same. However it does not always produce the best material utilisation. It can be the case that a part (which is set to 0 or 180) will fit better if it were set to (90 or 270) and would result in a better utilisation.
I've not seen commercial nesting software that does provide the option per part: try (0 or 180) and try (90 or 270)
Sadly SVGnest does not provide this option either.
However, having taken a look at Jacks code there is a routine that places parts with the help of a genetic algorithm (GA). I think it is in this section that a code change should be made to accomodate the (0 or 180) or (90 or 270) rules. However I'm totally not into GA. Is there anyone who can help to get this done?
I have included a sample. Start with the "example.svg". Set part distance:10 and enable "explore concave areas". This wil result in a nest like "result.svg" (You might wonder where the 3 indentations in the bin are for: These are the reserved areas where the lasercutter places its clamps to move the metal sheet under the laserbeam) The goal would be to let have the same colored parts the same orientation.
Hopefully someone will be helpfull.
it is great, i enjoyed your software. thanks for sharing.i think how we can make better in optimization. any way thanks very much
I'm trying to pack my shapes for a bookshelf using SVGNest. I've been successful using it in the past for other projects. But it seems to think my path is a bunch of smaller paths for the curved shapes.
My workflow was Fusion 360 -> DXF -> Inkscape.
Here is a pastebin with my SVG: Bookmark.svg
I make a lot of jewelry and this would be hugely useful if it kept groups of objects together.
Hi, I just discovered this project and I have some feature requests.
Will be practical to be able to save every nested Sheet as a separate SVG file, instead to save only one file containing all the nested sheets like it is right now. I tested the online demo. Maybe an option when are multiple sheets to download all SVG files as a ZIP file will do the trick.
There's probably more than one application that can do packing, which one are you benchmarking against? (because this is a bit like saying "our toothpaste is 30% better than the next leadin brand"... there's no true information there =D)
The geometry part of this code depends on plain polygon objects which are lists of {x: y:} points and some worker threads that call the clipper library and a genetic algorithm.
The other half of this code decodes the SVG shapes, organizes them into inner and outer contours, and then linearizes the edges.
It would be very useful if this system were broken into two completely disconnected parts with a simple API between them (that just took the polygons and returned the transformations), because then I could use it for packing other shapes that might be generated within my own javascript UI.
I've tried to use the output of the demo as an input, because was having difficulty in using my test profiles. I noticed that when demo has been run with 0 spacing, the subsequent nesting performed on it gives some white filled shapes placed outside the bin, and many shapes wildly overlap.
If the demo is run with 0.5 spacing, using this output gives a fine result.
line 185 placementworker.js
// choose placement that results in the smallest bounding box
// could use convex hull instead, but it can create oddly shaped nests (triangles or long slivers) which are not optimal for real-world use
// todo: generalize gravity direction
Consider placing according to the lowest position of centre of gravity, as suggested in this paper:
"Algorithm for 2D irregular-shaped nesting problem based on the NFP algorithm and lowest-gravity-center principle"
LIU Hu-yao, HE Yuan-jun [2005]
If you translated each of your polygons so that its centre of gravity was at the origin (and the rotations were around this point), then this final scan of displaced points (allpoints and shiftvector stuff) would be unnecessary as you would merely need to find the lowest point of finalNfp.
There are times in a job where there are pieces that are required to be in certain locations - due to grain or wood imperfections, etc. After these pieces are located in their manually approved locations it would be desirable to nest remaining pieces. Sometimes it is as simple as the 'primary' pieces are paying for the job and need to be in the best parts of the material, and then the remainder of the material can be used to nest pieces of 'secondary' value.
Note: this is NOT a duplicate request to the 'piece orientation' request - but obviously I'd mark the primary pieces by location and orientation.
Implementation thought: When the initial nesting container is selected and the process triggered, anything already within the container boundaries is treated as locked both positionally and with regard to orientation. Nesting resumes from there?
Clicking on the Demo button using Chrome version 49.0.2623.0 canary (64-bit) under OSX only gives an error in the bottom of the app window.
TypeError: Cannot read property 'length' of undefined
Hello,
I've translated the functions in geometryutil.js into C# for a course project. The problem is that sometimes the polygonHull function may lose several parts in the process. I've been captured that overlapping points with the one on the upper half of A and the other is in the lower cause the problem. Still, there are lots of problems cases I cannot handle.
I wonder if there is another feasible and reliable mean to create the hull of the parts?
thx in advance
i can run demo on the web site http://svgnest.com/.
however it reports errors when i download the file and run on the chrome version 60.
the error is shown in follow:
Any guidance would be appreciated. thank you
Uncaught DOMException: Failed to construct 'Worker': Script at 'file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/eval.js' cannot be accessed from origin 'null'.
at Parallel._spawnWorker (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/parallel.js:167:12)
at Parallel._spawnMapWorker (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/parallel.js:217:24)
at Parallel.p._spawnMapWorker (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/svgnest.js:351:47)
at file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/parallel.js:265:10
at Operation.then (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/parallel.js:51:5)
at Parallel.map (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/util/parallel.js:263:18)
at SvgNest.launchWorkers (file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/svgnest.js:354:6)
at file:///C:/Users/Administrator/Desktop/fdm%20scheduling/SVGnest-master/SVGnest-master/svgnest.js:235:25
Parallel._spawnWorker @ parallel.js:167
Parallel._spawnMapWorker @ parallel.js:217
p._spawnMapWorker @ svgnest.js:351
(anonymous) @ parallel.js:265
Operation.then @ parallel.js:51
Parallel.map @ parallel.js:263
SvgNest.launchWorkers @ svgnest.js:354
(anonymous) @ svgnest.js:235
Not able to download the final nested SVG. I tried to download svg after the demo nesting is finished. Got the below error on opening it.
This page contains the following errors:
error on line 1 at column 617: Attribute version redefined
Below is a rendering of the page up to the first error.
Chrome V54
When i nest this file, without filling space between parts - it is working
kolonest2.zip
When i try fill 10 or 20 value, it doesn't place my parts.
Any plans on porting this to C/C++ so that other language bindings (I.E. SWIG) can be made available?
When I uploaded the svg file:
An error is occurred.
TypeError: unable to get property "getAttribute" of undefined or null reference.
Has the file any error?
Will you give any samples in the demo project?
Hello,
when nesting attached SVG file with default-settings the"wrong placed " elements will not be recognized.
even increasing space between parts and curve tolerance shows "wrong placed" elements.
any ideas ( is the input svg not correct )?
thx in advance
Francois
What does "TypeError: element is undefined" mean exactly
Hello,
I make drawings on CorelDraw. I save them in SVG, open them in inkscape, ungroup everything, convert to path and save again.
Even so SVGnest does not generate a solution in a reasonable time.
Here the last SVG file I tried: https://goo.gl/86TEHx
In commercial software the nesting was conclued in less than 10 seconds.
Printscreen: https://goo.gl/qxHMMg
SVGnest is running now for more than 20 minutes and nothing happen. Windows Task Manager show me 99% CPU usage.
Printscreen: https://goo.gl/15L1eV
I'm trying with these configurations options: https://goo.gl/UVRZew
Hi Jack
Do you have a Google Plus profile? See https://plus.google.com/u/0/+ArthurWolf/posts/eVxYxnQCiHp (Thread on Arthur Wolf's - creater of the Smoothieboard - profiles)
Mm i dont know how its hard, but you must add DXF nestin mean cad nestin. This is to be good for me :)
for nesting for vinyl cutters / printers do options exist to?
nest within grid? where nested svgs are nested only horizontal or vertical?
keep svgs as graphics. assuming we are trying to nest svg of git hub logo, apple logo, ubuntu logo, and facebook logo, and each is made from multiple paths and groups can nesting be set to keep artwork the same ? in other words nest using the outer bbox or size?
thanks!!!
Currently it doesn't do anything. To start all over had to refresh the site. At least in chrome
I was wondering if there were any plans for a local command-line base version of this software. As the code seems to involve a lot of floating-point math, I think it would benefit from a CUDA implementation / GPU acceleration, which isn't currently possible with the Javascript base. Obviously, a local version would come before such optimization, but I was wondering if there were any plans to go in this direction.
If cutting some items, even if they are drawn out, some might be very similar. It would be nice to attach a label to each piece (possibly a number, with an optional text field - think 20 to 30 characters or so).
This 'legend' could be separate from the parts, but would need to be associated with each part both before and after optimization, so the parts can be identified for use later.
Sorry if this is to wordy. This should be a long term enhancement, not something I expect could be quickly done.
Thanks for your consideration.
I would like to suggest allowing some parts to be marked to have a 'grain' direction, as well as the stock piece.
This would allow cutting, say plywood, so the grain is going in the 'correct' direction for the part.
This is important in woodworking to keep the grain right, but also in patterned stock of any kind (wall paper for example).
Thank you for the consideration.
Hello,
Is that possible that the code fills the holes, for example an "O" characters inside?
I have some ideas for acceleration if you like it. For example using angles that pre-caclulated on polygons etc, to obtain the likely possible best rotation to fit to the cutout etc.
I'm not sure if I drew it correctly, but this input:
Produces this output after 700 iterations:
Forcing rotations to 1 thus decreasing incorrect combinations, and you can see there is one triangle left to be solved yet.
I attach here the svg zipped:
I'd like to take a shot at helping to abstract the algorithmic code from the DOM-dependent code so nests can be ran on a server /lambdas. Would also help keep things modular.
Any guidance would be appreciated, what would be your interest level?
I think this tool would be great for figuring out efficient cutting for fabric as well, however with some fabric it is essential that none of the parts get rotated at all due to the fabric structure.
Setting "Part Rotations" to 0 or 1 still caused the parts to be rotated, I would suggest an option to not rotate any parts.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.