"Project on Surface" using Scripting.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: "Project on Surface" using Scripting.

Post by onekk »

mfro wrote: Sun Jul 31, 2022 7:53 am ...
Thanks I will study the code.

At a first glance it is interesting, and seems working, from your inages at least if I'm on mobile I can't test myself.

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
mfro
Posts: 666
Joined: Sat Sep 23, 2017 8:15 am

Re: "Project on Surface" using Scripting.

Post by mfro »

Here's a simplification for the final loop. It's functionally equivalent, but maybe easier to read. It turned out Compounds and Shells can be handled equally.

Code: Select all

for section in zip(faces1, faces2):
    if (section[0].ShapeType == 'Shell' or section[0].ShapeType == 'Compound'):
        # if we receive a Shell/Compound, it contains a single Face with multiple Wires where
        # the first one represents the outer shape and subsequents represent holes in it
        w = [section[0].Shells[0].Faces[0].Wires[0], section[1].Shells[0].Faces[0].Wires[0]]
        l = Part.makeLoft(w, True)

        for w in zip(section[0].Shells[0].Faces[0].Wires[1:], section[1].Shells[0].Faces[0].Wires[1:]):
            subtractive = Part.makeLoft(w, True)
            l = l.cut(subtractive)
            
    elif (section[0].ShapeType == 'Face'):
        # extract wires from Face
        w = [section[0].SubShapes[0], section[1].SubShapes[0]]
        l = Part.makeLoft(w, True)

    Part.show(l, f"letter_{cnt}")
"faces" should be renamed (to "sections{1|2}", maybe) as these aren't always faces
Cheers,
Markus
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: "Project on Surface" using Scripting.

Post by onekk »

mfro wrote: Sun Jul 31, 2022 7:53 am ..

Many Thanks, I have modified sligtly your code, only to adapt to my code and my editor linter for sources.

I modified the license to CC-BY-NC-SA to permit redistribution and building upon the presented code if someone wants to transform it in a proper macro:

@mario52 :lol:

EDIT: new version, incorporating @mfro changes:

20220731-text_on_surface.py
(9.06 KiB) Downloaded 34 times

Some notes:
  • I've tested it with some unicode characters and seems to work, but not for every characters, like those with face that resemble emoji that render only the "external circle".
  • It seems that Braille are supported.
  • and some language fonts, seems suported too.
But the test is done with "Dejavu Serif" only, and depending on glyphs are made in the fonts, your mileage may vary.
tx_on_surf_ch1.png
tx_on_surf_ch1.png (11.22 KiB) Viewed 934 times
tx_on_surf_ch2.png
tx_on_surf_ch2.png (7.32 KiB) Viewed 934 times
tx_on_surf_ch3.png
tx_on_surf_ch3.png (5.88 KiB) Viewed 934 times

Last some thanks and credits:

Many Thanks to @Chris_G and @mfro for the code help, let me know if the mention in the code are ok for you, or if you prefer some other things like name an email or something other. (PM me or post here according to your taste)

Again big thanks to @Chris_G for supporting and to have bear my bothering with code.

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
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: "Project on Surface" using Scripting.

Post by onekk »

Chris_G wrote: Thu Jul 28, 2022 8:25 am ...
Hello, I'm trying to expand my scripting guide incorporating your code to show some concepts.

Now I'm stuck with this portion of code:

Code: Select all

c, fp, lp = quad.curveOnSurface(e)
mapped_edges.append(c.toShape(surf, fp, lp))
I don't find information about the origin of the:

Code: Select all

c.toShape(surf, fp, lp)
I know that the result is the projection of the curve c on the surface using his fp and lp parameters.

But I can't get from what part of FC is derived from.

something like:

Code: Select all

help(Part.Something.toShape)
But what is the Something

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/
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: "Project on Surface" using Scripting.

Post by edwilliams16 »

onekk wrote: Tue Aug 30, 2022 3:41 pm

Code: Select all

c.toShape(surf, fp, lp)
I know that the result is the projection of the curve c on the surface using his fp and lp parameters.

But I can't get from what part of FC is derived from.

something like:

Code: Select all

help(Part.Something.toShape)
But what is the Something

Regards

Carlo D.

Code: Select all

help(Part.Geom2d.Line2dSegment.toShape)
but nothing about the fp, lp parameters.

You can see indication of that in the source in https://github.com/FreeCAD/FreeCAD/blob ... ometry.cpp
search on toShape. It appears to be a wrapper around OpenCascade.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: "Project on Surface" using Scripting.

Post by onekk »

edwilliams16 wrote: Tue Aug 30, 2022 7:38 pm
but nothing about the fp, lp parameters.

You can see indication of that in the source in https://github.com/FreeCAD/FreeCAD/blob ... ometry.cpp
search on toShape. It appears to be a wrapper around OpenCascade.
You are speaking around lines 579 584 about GeomCurve.

I will check eventually OCCT sources if there is something. It is to make some correct or better not too wrong affirmation.

I hope that Chris_G will show up prior to write insanities. :D

Thanks

Regards
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
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: "Project on Surface" using Scripting.

Post by Chris_G »

Here are the python class that implements toShape() with the parameters arguments :
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L111
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L185
They are abstract classes that are inherited by the python Geom/Geom2d curves.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: "Project on Surface" using Scripting.

Post by Chris_G »

edwilliams16 wrote: Tue Aug 30, 2022 7:38 pm but nothing about the fp, lp parameters.

You can see indication of that in the source in https://github.com/FreeCAD/FreeCAD/blob ... ometry.cpp
search on toShape. It appears to be a wrapper around OpenCascade.
I think it is the main purpose of the (App) Part module : implement a C++ and a python wrapper around OCCT.
And from what I saw, the C++ API is less developed than the python API.
Because, when you work in C++, you can often work directly with the OCCT objects, so you don't need all the useful functions to be re-implemented.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: "Project on Surface" using Scripting.

Post by onekk »

Chris_G wrote: Tue Aug 30, 2022 9:03 pm Here are the python class that implements toShape() with the parameters arguments :
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L111
https://github.com/FreeCAD/FreeCAD/blob ... p.cpp#L185
They are abstract classes that are inherited by the python Geom/Geom2d curves.
Thanks I will study sources.

At a first glance I don't find find the (surf, u1, u2) or similar method that is invoked, and probably is my fault as I'm checking with a Smartphone.

Later asap I will have a real computer I will check better.

EDIT:

From: https://dev.opencascade.org/doc/occt-7. ... ml#details

void Init (const Handle< Geom2d_Curve > &C, const Handle< Geom_Surface > &S, const Standard_Real p1, const Standard_Real p2)
This could be the description associated to the function?
two real values p1 and p2 which are the parameters for the vertices V1 and V2 on the curve. The curve may be defined as a 2d curve in the parametric space of a surface: a pcurve. The surface on which the edge is built is then kept at the level of the edge.
END EDIT

Thanks again and 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/
Post Reply