Macro to draw folding lines on a loft

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

But your oblong to round isn't drawn correct, the mid section would be a flat triangle. I was in sheet metal for quite a few years, and the loft doesn't work for standard sheet metal fittings.

Granted the loft would work, but I think lofting ends separate from center would be more accurate.

But I am going to study over this more.

Edit:

The one you have in green is more accurate but the loft doesn't usually draw it that way.

Or did you get it to draw it like that?
Attachments
ob_rnd4.png
ob_rnd4.png (40.8 KiB) Viewed 1036 times
User avatar
nm2107
Posts: 42
Joined: Sun Feb 20, 2022 10:37 pm

Re: Macro to draw folding lines on a loft

Post by nm2107 »

The one you have in green is more accurate but the loft doesn't usually draw it that way.
Indeed, FreeCAD does not place loft lines in a manner that is unfoldable. From the green loft picture, it is just the standard loft, plus the macro executed on it (the macro drawn the folding lines on the 3D shape). The macro works for this oblong to circle case, but isn't very useful for other cases (c.f. my previous comment).

I agree with your picture, how did you get to have such loft ?

When I started the macro, I was hoping that it could detect where to place the folding lines regarding the loft's top and bottom faces (i.e. the wires on the top and bottom faces). But as FreeCAD is building lofts in a manner that is not developable, maybe the macro should create the loft itself, i.e. should start from the top and bottom sketches. Doing so, it could place the folding lines using the sketches directly, and then maybe create ruled surfaces between the folding lines. However, this would only make a shell (i.e. no thickness).
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

how did you get to have such loft ?
It's not one loft, it's three. The sides are separate semi circles (180 degree arcs), and middle triangle is from a wire upgraded to face.
I use part, not part design.

I am still fairly new to python, (about 6 months now) and still learning.

Look at my links, the fitting @edwilliams16 programmed with mesh. I am nowhere near that advanced. However I can triangulate one with no problem.

Most standard symmetrical fittings can easily be programmed, it's when one has crazy offsets that it's more difficult.

When symmetrical a 1/4th is all that's needed, image example only, more segments would be used.
Attachments
ob_rnd5.png
ob_rnd5.png (6.38 KiB) Viewed 954 times
User avatar
nm2107
Posts: 42
Joined: Sun Feb 20, 2022 10:37 pm

Re: Macro to draw folding lines on a loft

Post by nm2107 »

Most standard symmetrical fittings can easily be programmed, it's when one has crazy offsets that it's more difficult.
Do you plan to program one function by use case (i.e. for oblong to circle, for square to circle, etc...) ? That'd be cumbersome IMHO, I think it'd be worth it to find a way which would be able to identify where to place the folding lines for each cases (as for each case the unfolded shape can also vary in function of the planar orientation of the top and bottom faces).


I agree with the 1/4 mention when parts are symmetrical on two planes.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

I use points like the distance between two points and angles between lines, in other words just basic analytic geometry to triangulate.

I prefer that over mesh.

On mobile now, I'm going to give a better example when on desktop.

Edit:

Back on desktop. I am working on a way to auto set certain points, so far I manually set them, and have a script to triangulate.

I layout as though I am inside the fitting and I turn counter clockwise for each section. That way the layout is correct you have the inside of the fitting to fold up.

Examples only, many times such a fitting is laid out in four separate pieces, depending on size.

You might like this:

https://wiki.freecad.org/Macro_Cut_Line

It works on arcs also, and you can set points. However some points, depending on shape still have to be manually set.

Edit 2:

You can also loft or ruled surface from arc to arc and treat the triangle separate. I just haven't figured all this out in code yet. Drawing attached.

Continued next post, remember you have mesh also.
Attachments
rf1.FCStd
(11.02 KiB) Downloaded 15 times
f1.png
f1.png (9.8 KiB) Viewed 843 times
f2.png
f2.png (15.93 KiB) Viewed 843 times
f3.png
f3.png (15.3 KiB) Viewed 843 times
f4.png
f4.png (13.01 KiB) Viewed 843 times
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

Here I did one using mesh another using triangulation.

Note for a mesh, entity has to have a small slit in it. See images:

Also mesh unrolled it where you have the outside, I rotated it.
Attachments
f5.png
f5.png (15.02 KiB) Viewed 809 times
f6.png
f6.png (28.41 KiB) Viewed 809 times
User avatar
ThanklessLiving
Posts: 99
Joined: Sat May 30, 2020 1:49 pm

Re: Macro to draw folding lines on a loft

Post by ThanklessLiving »

Very interesting and useful stuff here

It would be ideal to have this functionality in the sheet metal workbench so that it can unfold normal bends, large radius bends (to be formed either by rolling or with multiple bends) and also other weird surfaces all in the same part.
User avatar
nm2107
Posts: 42
Joined: Sun Feb 20, 2022 10:37 pm

Re: Macro to draw folding lines on a loft

Post by nm2107 »

Thank you jfc4120 for your detailed answer ! :D

I see that you're connecting the top face and bottom faces points to make folding lines by the order of points selection. And of course, this mechanism works well :D , nice work !

I'd like to avoid the manual points selection in order to make the folding lines determination faster (e.g. select top and bottom faces sketches, invoke the macro and that's all).

I'm thinking about the following process :
- determine a max number of folding lines (e.g. based on an angle, like 10° so 360° / 10° = 36 folding lines ; or based on a distance between each folding lines, which would be applied on the smaller sketch).
- for each sketch, split the non linear edges into chunks, depending on the amount of max folding lines and also the length of the non linear edge.
- place a point on each chunk start
- once all the points are placed, I have to connect them in order to make folding lines. I'm thinking about this process :
- for each points of the A sketch, project it on the B sketch along a vector that is passing by the two sketches centers. From the projection point, look at which sketch point is the closest : that's the point that we should link to the point which has been projected (so our folding line is done). Repeat for all the other points to make the remainning folding lines.
- To draw the flattened representation, use triangulation as usual.

I still have to try this process, as I'm not sure whether the points connection step will work or not.

Note for a mesh, entity has to have a small slit in it.
Yes, I've also noticed that when using a complete 3D shape, the mesh unfold doesn't know where to start / end, and produces incoherent output. I usually cut the 3D shape in two pieces using a plane, and unfold the two halves of the 3D shape. Then I place the two flattened shapes next to each other to re-create the full flattened shape.

I see that you're applying the CutLine macro to the 3D shape before using the mesh unfold feature, I wasn't aware of such technique (I usually cut the shape with planes, or use polygons to draw the top and bottom shapes instead of circles).

I think I'll create a git repository for the macro, it'll be easier to work with.
User avatar
nm2107
Posts: 42
Joined: Sun Feb 20, 2022 10:37 pm

Re: Macro to draw folding lines on a loft

Post by nm2107 »

I've made some progresses regarding the determination of the points for each sketches (c.f. my previous comment).

Now I have to connect such points in order to form folding lines. I tried to use the projection idea I described on my previous comment, but it is not adequate.


With the points of the square-ish wire projected on the circular face :
Screenshot from 2023-03-12 15-27-48.png
Screenshot from 2023-03-12 15-27-48.png (40.3 KiB) Viewed 729 times
With the points of the circular wire projected on the square-ish face :
Screenshot from 2023-03-12 15-28-03.png
Screenshot from 2023-03-12 15-28-03.png (44.43 KiB) Viewed 729 times
Both, superposed :
Screenshot from 2023-03-12 15-28-15.png
Screenshot from 2023-03-12 15-28-15.png (57.74 KiB) Viewed 729 times
Also, you can see that the point on the circle wire which should form a triangle flat face is only connected once (i.e. to one folding line instead of two) :
Screenshot from 2023-03-12 15-28-15-2.png
Screenshot from 2023-03-12 15-28-15-2.png (68.93 KiB) Viewed 729 times
For now I don't know how to connect the points properly, I'll try to dig into it.
c.f. this PR : https://github.com/nm2107/FreeCADLoftFo ... nes/pull/1
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

select top and bottom faces sketches, invoke the macro and that's all
Yes would work for regular fittings, but when one face vertex count is different it won't work. I.e., see the single triangle image I showed.

But points still work, but the program would have to be tweaked in such a case to account for the difference.

I still can't get your program do work. See attached drawing.

I get this error:
File "C:/Users/Owner/AppData/Roaming/FreeCAD/Macro/test_generatrices.FCMacro", line 15, in <module>
def getIntersectionPoint(line: Part.Line, wire: Part.Wire) -> FreeCAD.Vector | None:
<class 'TypeError'>: unsupported operand type(s) for |: 'type' and 'NoneType'
Edit:

Sorry forgot to attach file: Now attached.
Attachments
jimtest.FCStd
(10.12 KiB) Downloaded 15 times
Post Reply