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!
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 »

unsupported operand type(s) for |: 'type' and 'NoneType'
oh it looks like your python version is too old (probably before python 3.10 :/). Maybe I should drop these typehints...

From your example file, I get the following results from my current `master` branch (select top and bottom faces and invoke the macro) :
Screenshot from 2023-03-12 21-19-54.png
Screenshot from 2023-03-12 21-19-54.png (19.45 KiB) Viewed 938 times
Screenshot from 2023-03-12 21-20-11.png
Screenshot from 2023-03-12 21-20-11.png (25.17 KiB) Viewed 938 times
And from my PR #1 (select both sketches and invoke the macro) :
Screenshot from 2023-03-12 21-24-38.png
Screenshot from 2023-03-12 21-24-38.png (13.75 KiB) Viewed 938 times
Screenshot from 2023-03-12 21-24-45.png
Screenshot from 2023-03-12 21-24-45.png (13.37 KiB) Viewed 938 times
Screenshot from 2023-03-12 21-24-56.png
Screenshot from 2023-03-12 21-24-56.png (20.89 KiB) Viewed 938 times
This works for such simple cases, but not for more complex ones (such as the rectangle with rounded corners to circle loft).
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.
Yeah, the easier way is to have a 1:1 mapping on both sides, but for some lofts it is not possible (e.g. perfect square to circle : 4 points vs n points). On my PR#1 I'm able to place such points, but I have no idea how to connect them (they aren't created by walking the wire in a particular direction, but by walking the wire's Edges array, which is not ordered as if you'd walk the wire).


EDIT :
Look at my links, the fitting @edwilliams16 programmed with mesh.
Do you have a link to this fitting ?
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 attached your test file saved with the macro result from my PR#1.
Attachments
jimtest_pr1.FCStd
(22.02 KiB) Downloaded 13 times
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

I have:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Help 1.0.3
What freecad version do you use. Mine is latest stable release.

Edit:
Look at my links, the fitting @edwilliams16 programmed with mesh.

Do you have a link to this fitting ?
Top
Yes, it in one of the replies here: viewtopic.php?p=610974#p610974 for download.

Also attached here, I slightly modified.

Have a look at a new question I have here viewtopic.php?t=76745

Edit:

I tried the latest nightly build, it gave me the radial lines for cone, but no layout.

See image, that's all I get, this version is:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.31917 (Git)
Build type: Release
Branch: master
Hash: 4639283b459f9ff9093e289908cc003db8745b82
Python 3.10.9, Qt 5.15.6, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Help 1.0.3
Attachments
jt.png
jt.png (27.83 KiB) Viewed 877 times
sq_rnd_spreadsheet.py
(11.77 KiB) Downloaded 12 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 »

it gave me the radial lines for cone, but no layout.
Yeah it's my bad, I forgot to push the part which draws the flat rep :/ , sorry about that. I just pushed it, you can grab it at this commit : https://github.com/nm2107/FreeCADLoftFo ... es.FCMacro

I'm using FreeCAD version 0.20.2, on a GNU/Linux host (installed via Flatpak, commit https://github.com/FreeCAD/FreeCAD/comm ... 3cad8c5cb8). The python version used by FC is 3.10.6.
Yes, it in one of the replies here: viewtopic.php?p=610974#p610974 for download.
Oh yes, I saw it, thanks :) . It looks like it is dedicated to square to circle loft, whereas I'd like to find a way to place the folding lines no matter the loft kind.

I'll check out your other question, thanks ;)
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

@mm2107 I will test, and later I will private message you about something.

Edit:

Worked good. I am attaching a macro. Run it and then hit home.

It has user interface. It is used in draft mode. Seems your technique needs sketches. It would be good just to have the bottom and top face, maybe in draft, and lay them out.

The attached file doesn't lay out, it just draws skeleton of fitting, then I place the points to layout.

But just suggestions, I myself would not like to have to use sketcher for fittings. Or is there another way?
Attachments
Rect_transition.py
(1.7 KiB) Downloaded 13 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 »

Yes, I was able to run your macro :
Screenshot from 2023-03-13 22-43-20.png
Screenshot from 2023-03-13 22-43-20.png (67.43 KiB) Viewed 797 times
Regarding the sketches usage, I think I prefer to work with them for now for the following reasons :
- can use parametric dimensions (e.g. via spreadsheets)
- can be created from other shapes (via shape binders, via "wire to sketch" from Draft WB)
- can be selected as a whole object

However, the macro makes use of `sketch.Shape` which returns the Wire (TopoShape in 3D space), so adapting the script for wires selection instead of (or in combination with) sketches selection won't require a lot of changes (will happen in the `getWiresFromGuiSelection` function).
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

Did you ever look at @edwilliams16 square to round?

Also how are you positioning the top sketch, I had to use a datum plane.

I look at sketcher more for things that a machine shop uses, not sheet metal, meaning ductwork type fittings.

I am going to experiment a little more however.

Edit:

I see that part design isn't required, I downgraded 2 circles to wires, draft to sketch, and worked. That is good....
Maybe you can automate some of this.

Edit: here is one of your examples triangulated (half pattern): See image.
Attachments
g9.png
g9.png (14.53 KiB) Viewed 754 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 »

Did you ever look at @edwilliams16 square to round?
Yes I gave a look to the `sq_rnd_spreadsheet.py` file you posted, this is interesting, thank you for sharing it. However, this is for one use case only (i.e. square to round), and I'd like to find a way do draw the folding lines no matter the X to Y shape transition ^^.
I see that part design isn't required, I downgraded 2 circles to wires, draft to sketch, and worked. That is good....
Yeah FreeCAD has a nice way of representing things (topological and geometrical, Shape base class, etc...), and nice tools to operate with elements (draft up/downgrade). For now, the macro I wrote requires the selection of two sketches, because this is how I'm working with it. Internally, I'm using the wires out of the selected sketches, so it'd require only a small tweak to support wire selection directly (c.f. my previous comment).

For now my code is still very messy, I'm mostly poking around trying to find a way to place the folding lines correctly, and then flatten them.
Next, for production usage, it would be good to support not only sketches selection, and to also have the flatten representation be updated when the base wires are changed (would potentially require to turn the macro into a WB).

And one step further, be able to draw folding lines on shapes where the top and bottom faces aren't planar (such as a tube junction).

As you can see the roadmap of this project is big (I haven't expected it like that to beb honest ^^), and I'm only at the very beginning of a POC :p
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Macro to draw folding lines on a loft

Post by jfc4120 »

Did you get my PM?

I am in the process of converting many fittings from basiccad (In Designcad) to freecad python.

Another example, see images:

But eventually, I would like to see a combination of your code and my code to layout a variety of fittings.

But I can already tell you, one single program isn't going to handle every fitting. But maybe 3 or 4 different variations of the program would probably handle most of the common fittings.

Edit:

I can already tell you, your code is more advanced than mine in freecad. I only know how to use geometry.

Your code and @edwilliams16 code is over my head. I am guessing your code is things unique to freecad python, am I correct?
Attachments
f15.png
f15.png (7.68 KiB) Viewed 666 times
Last edited by jfc4120 on Wed Mar 15, 2023 6:23 am, edited 2 times in total.
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 am guessing your code is things unique to freecad python, am I correct?
Yes, it is dedicated to FreeCAD API. However, how it works could be applied elsewhere I guess, but it would need a rewrite to fit the newplace API.

Screenshot from 2023-03-14 21-20-52.png
Screenshot from 2023-03-14 21-20-52.png (73.62 KiB) Viewed 625 times
I managed to find a way to triangulate the right edges (by comparing the dot product of the planes axis and a vector going through the middle of the straight edge and any other points on the opposite face to test ; the tested point which gives the higher dot product is retained to make the triangle).

I tried to apply this dotproduct comparison for other vertices, but it doesn't fit. Actually the output is coherent with what the dotproduct does : simply compares vectors orientation (inclination). Comparing the vertices on a single value (vector length; dotproduct; vector distance, etc...) isn't efficient enough I guess.

Regarding your example, I think it is yet another case (not simply a loft, but a sweep).
Post Reply