[Not] Nesting parts with A2plus workbench

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
jamtek
Posts: 40
Joined: Sun Oct 04, 2020 6:33 pm
Location: 27th Lat., Florida

[Not] Nesting parts with A2plus workbench

Post by jamtek »

EDIT: please read though the comments, there is a much more efficient way to nest part directly in the Path WB.

I happened to come across a YouTube video from Aalto FabLab that showed a workflow to nest all the parts from a Part Design model onto a defined piece of stock, which I though was very clever.
https://www.youtube.com/watch?v=kbu4pEzIPl4

It was a lightbulb moment for me, as I have been struggling to find an easy way to nest parts from my FreeCad models before creating tool paths for my CNC machine.

In the video he defines and adds a part called stock to his Part Design model. He then exports all the individual parts to step files and then re-imports them to an A2plus assembly file.
PD_stock.png
PD_stock.png (98.66 KiB) Viewed 3502 times
However, I find it's more streamlined to click on the 'Add shapes from an external file' button from inside the A2plus workbench and import the selected parts directly from the FreeCad part design file. I then make sure that only the stock part's fixed Position is set to True. Set the parts to be to parallel and plane coincident with the stock.
a2plus_import.png
a2plus_import.png (7.92 KiB) Viewed 3502 times
It's not an automatic process, as you have to use 'Transform' to position the pieces in the stock, but it was straight forward enough for me to get parts ready for the Path work bench.
nested.png
nested.png (108.13 KiB) Viewed 3502 times
I hope someone finds this useful.

Cheers,
Jamtek
Last edited by jamtek on Sun Jul 10, 2022 6:07 pm, edited 1 time in total.
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Nesting parts with A2plus workbench

Post by thomas-neemann »

jamtek wrote: Sun May 30, 2021 8:37 pm ...
It's not an automatic process, ...


here is a suggestion with automatic process using this open source software

https://deepnest.io/


1.png
1.png (48.72 KiB) Viewed 2095 times

Bildschirmfoto_2022-06-06_07-44-20.png
Bildschirmfoto_2022-06-06_07-44-20.png (116.29 KiB) Viewed 2088 times



https://www.youtube.com/watch?v=t3i-y-PKZ-c


phpBB [video]
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Nesting parts with A2plus workbench

Post by MRx »

just for your information deepnest.io converts the nested picture via an online service, the picture will be uploaded to deepnest.io and the dxf file will be downloaded as a result. It's not a complete standalone version.

it converts the svg data via:
http://convert.deepnest.io/

and the dxf output has some issues with freecad
https://forum.freecadweb.org/viewtopic.php?f=3&t=68997
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Nesting parts with A2plus workbench

Post by chrisb »

http://svgnest.com/ are probably better to handle. As far as I know is Arch Nest based on it. What's the problem with the latter (I have never used it).
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Nesting parts with A2plus workbench

Post by sliptonic »

The method shown in the original video seem very inefficient to me. When you create the Path job, it creates a clone of each of the models for you. Those models are independently positioned within the stock. The job setup tab has tools for orienting the parts, setting the z position, rotating and translating them. So the entire process of exporting and importing them appears redundant.

With regard to automatic nesting, that is definitely something I would like. Both Deepnest and svgnest are written by the same guy. They both use the same (very good) nesting algorithm but are implemented in javascript. Unfortunately both projects appear abandoned there's very little work going on. It would be great if someone would re-implement the nesting algorithm in python.

It would also be possible to write an add-on workbench or tool that takes the existing job solids, exports the polygons, makes a call to an external nesting service, gets back the result and applies the translation to the part solids. That can all be done manually now. The workflow could be automated pretty easily, I think.

Here's a good thread
https://forum.freecadweb.org/viewtopic.php?f=15&t=33485
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Nesting parts with A2plus workbench

Post by onekk »

sliptonic wrote: Mon Jun 06, 2022 3:55 pm Unfortunately both projects appear abandoned there's very little work going on. It would be great if someone would re-implement the nesting algorithm in python.
Some consideration as I have tried in the past to make something similar, so maybe my consideration are dated.

This is not so trivial, as you have to add an "enlarge" to all the objects to have space for "tool diameter" when cutting parts.

I have gave an eye to the code, and from what I remember, the code was intended for "laser cutting" where the "tool diameter" is "very small" so it is not a problem.

These algorithms are base usually on "Convex Hull" and from what I see there is no "fast convex hull" library around for python.

Solution of transforming the shapes in SVG and "recompute back" transformations could be viable, if the external program will return some reference to the original shapes to permit:

1) a map from shapes to "svg contour"
2) the result have a reference to the "svg contour" to get back to the original shape
3) the result have the rotation information or a rotation could be easily computed from the "original svg" to the "returned svg"

I think that the blocking points could be overcome with some clever people working together, but there are other ways, sadly many of them are using algorithm not "freely available".

But as usual this is only my personal point of view.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Nesting parts with A2plus workbench

Post by sliptonic »

onekk wrote: Mon Jun 06, 2022 4:51 pm This is not so trivial, as you have to add an "enlarge" to all the objects to have space for "tool diameter" when cutting parts.
That's pretty easy for us since that's exactly what clipper (libarea) does. We take the tool radius and use it to offset the polygon to get the 'enlarged' part. It even works if the nesting algo can place small parts in the 'holes' of large ones.
Solution of transforming the shapes in SVG and "recompute back" transformations could be viable, if the external program will return some reference to the original shapes to permit:

1) a map from shapes to "svg contour"
2) the result have a reference to the "svg contour" to get back to the original shape
3) the result have the rotation information or a rotation could be easily computed from the "original svg" to the "returned svg"
I think that's all addressed in julian's macro in the thread I linked to.
The only downside with his approach is the manual requirement to export the svg, upload it to svgnest, manually control the process, and then download again. Most of that is because svgnest doesn't have an api.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Nesting parts with A2plus workbench

Post by onekk »

sliptonic wrote: Mon Jun 06, 2022 5:00 pm I think that's all addressed in julian's macro in the thread I linked to.
The only downside with his approach is the manual requirement to export the svg, upload it to svgnest, manually control the process, and then download again. Most of that is because svgnest doesn't have an api.
Thanks, for the reply.

From what I could remember the nesting algorithm is not too complicated as it select the pieces using a convex hull or a bounding box and then position the most big, and then try to place all the remaining in the space left, trying to rotate them.

From what I have seen, it is not impossible to translate the javascript code to python, the only problem I have found when I've tried was to obtain the "convex hull" in a fast way,

So it mainly done using loop that scans "shape list" and this is not a big hassle for python, If i didn't go wrong the blocking point was the "convex hull" and the rotation part, but for rotation, FC has no problems.

I don't remember if there are other checks after having applied the "convex hull" as for some shapes it is not very efficient as in U shaped "shapes" it could lead to "holes" in the positioning with large area not used.

Probably if there are around some python accessible "Convex Hull" algorithm (I think that a C++ library with Python API) probably it could be done even in a Macro, or WB.

But these consideration are done using my memory from some time ago (at least three years) so they are not precise.

Maybe when I have time I will try to do some more research.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
jamtek
Posts: 40
Joined: Sun Oct 04, 2020 6:33 pm
Location: 27th Lat., Florida

Re: [Not] Nesting parts with A2plus workbench

Post by jamtek »

When I posted the link to YouTube video Aalto University Fab Lab had done. I assume it was not apparently obvious to video creator or myself how to flatten and manually nest parts directly in the Path work Bench for the flat-pack furniture assembly. Also, I'm aware of the SVGNest, DeepNest tools and they are great resources for wood workers, thanks.

Being able to do all this natively in FreeCad with just the Part WB and Path WB is amazing! Big shout out to @sliptonic and all the Freecad developers who have worked on the Path WB. FreeCad continually shows that it can punch above it's weight and offer feature that match commercial CAD software.

Here is a quick GIF of flattening and arranging the assembly in around a minute in Path WB.
Attachments
Peek 2022-07-10 13-14.gif
Peek 2022-07-10 13-14.gif (900.68 KiB) Viewed 1549 times
Post Reply