How to use Path.fromShapes ?

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

How to use Path.fromShapes ?

Post by onekk »

I'm doing some experimenting with Path creation, simply some tests, but I encounter this strange behaviour:

I'm using this code:

Code: Select all


points = (
    (0,0,0),
    (0,2,0),
    (2,2,0),
    (3,3,0),
    (3,2,0),
    (0,0,0)
)

wire = Part.makePolygon(points)

Part.show(wire, "Wire")

o = DOC.addObject("Path::Feature","myPath2")
o.Path = Path.fromShapes((wire))

DOC.recompute()

p =  o.Path

print(p.toGCode())
and I'm obtaining this Gcode:

Code: Select all

G90
G17
G0
G0 X3.000000 Y3.000000
G1 X3.000000 Y3.000000 Z0.000000
G1 X3.000000 Y2.000000 Z0.000000
G1 X0.000000 Y0.000000 Z0.000000
G1 X0.000000 Y2.000000 Z0.000000
G1 X2.000000 Y2.000000 Z0.000000
G1 X3.000000 Y3.000000 Z0.000000
I'm expecting to find the last move to be:

Code: Select all

G90
G17
G0 X0.000000 Y0.000000 Z0.000000 # first point
G1 X0.000000 Y2.000000 Z0.000000 # second point
G1 X2.000000 Y2.000000 Z0.000000 # third point
G1 X3.000000 Y3.000000 Z0.000000 # fourth point
G1 X3.000000 Y2.000000 Z0.000000 # fifth point
G1 X0.000000 Y0.000000 Z0.000000 # ending point the polygon is closed
or maybe as some values are not modified with this writing:

Code: Select all

G90
G17
G0 X0.000000 Y0.000000 Z0.000000  # first point
G1 Y2.000000                      # second point
G1 X2.000000                      # third point
G1 X3.000000 Y3.000000            # fourth point
G1 Y2.000000                      # fifth point
G1 X0.000000 Y0.000000            # ending point the polygon is closed
Or maybe I'm doing something wrong.

TIA 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/
herbk
Veteran
Posts: 2657
Joined: Mon Nov 03, 2014 3:45 pm
Location: Windsbach, Bavarya (Germany)

Re: How to use Path.fromShapes ?

Post by herbk »

Hi Carlo,

PfS is a relict of the old Path WB before FC 0.17. If you use it, the path is allways created outside the job and without tool compensation.

I know only how to use it using the UI, so may by thats not what you realy want to know...:

Select an edge of a part.
Click Path from Shape
Export Path with the Export to Gcode option of the menue (using the usual button dos not work)

What's nice at PfS: It creates a 2,5 D Path !
pfs.png
pfs.png (50.94 KiB) Viewed 1500 times
Edit: What i see now: The option Export to Gcode is not availible... So PfS is useless now and should be removed...
Attachments
path_from_shape.FCStd
(43 KiB) Downloaded 23 times
Gruß Herbert
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to use Path.fromShapes ?

Post by onekk »

Thanks, for the reply.

I wonder, as I'm still experimenting with Path Scripting, how to obtain some toolpaths, so I've seen the wiki page describing "Path Scripting".

If it is very old and buggy, maybe it is time to update or delete the page.

https://wiki.freecadweb.org/Path_scripting

Getting Path from Shape

And in the Python Console printing the __doc__ it says that the function cited (fromShape) is deprecated in favour of (fromShapes) and in effect the code seems to cope with various parameters to tune the creation of the Path.

As there is some request around to know better how Path Operation are created to implement new operation or simply to know better "Path internals", I was simply experimenting to see if some information could be obtained without "poking" developers, as the code is slightly involute to follow.

Using the Gui is not an option, as the goal is to create Path Operation starting from script.

I've created some working code, but I was stopped in some areas, like creating proper "holding tabs" and positioning them in desired places (where they don't create problems to be filed out, as I work with plywood and usually created crenelated interlocking parts)

But this is a peculiar use of Path, and usually many workaround have to be taken, I have had some help by @sliptonic and Russsel (@Russ4262 hope it is right) in this area, but I'm still experimenting.

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/
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: How to use Path.fromShapes ?

Post by Russ4262 »

onekk wrote: Thu Dec 30, 2021 5:06 pm I'm doing some experimenting with Path creation, simply some tests, but I encounter this strange behaviour:
I'm using this code:

Code: Select all

points = (
    (0,0,0),
    (0,2,0),
    (2,2,0),
    (3,3,0),
    (3,2,0),
    (0,0,0)
)

wire = Part.makePolygon(points)

Part.show(wire, "Wire")

o = DOC.addObject("Path::Feature","myPath2")
o.Path = Path.fromShapes((wire))

DOC.recompute()

p =  o.Path

print(p.toGCode())
and I'm obtaining this Gcode:

Code: Select all

G90
G17
G0
G0 X3.000000 Y3.000000
G1 X3.000000 Y3.000000 Z0.000000
G1 X3.000000 Y2.000000 Z0.000000
G1 X0.000000 Y0.000000 Z0.000000
G1 X0.000000 Y2.000000 Z0.000000
G1 X2.000000 Y2.000000 Z0.000000
G1 X3.000000 Y3.000000 Z0.000000
...
Evening,
The g-code produced by the Path.fromShapes() is correct, except for a needed initial retraction to clearance/safe height before beginning the wire path. I created a Path Job containing a Custom op, and pasted your initial g-code produced (as quoted above) and it produces the correct path on the wire. I think what you are wanting is more control of the start point. You might even want the path to start with the first point provided to create the polygon. To solve these problems, and perhaps more, I suggest creating a Job and adding the wire as a model for the Job. Then create a Profile op based on the wire,and disable Tool Compensation. Also, you can then set the Start Point for the Profile op which will allow you to use that first point from the wire-creation code as the Start Point.

I do not know how the Path.fromShapes() algorithm determines the start point for a given shape. It appears the default algorithm choice for your particular example is (3, 3). If you want (0, 0), then I suggest the method mentioned above using the Profile op to allow a more conventional approach.

Just a suggestion. Thanks for sharing your scripting progress!

The screenshot is a Profile op without Tool Compensation and Start Point enabled with (0, 0) as value. I attached the source file.

Russell
Attachments
Polygon Wire.FCStd
(16.36 KiB) Downloaded 18 times
Snip macro screenshot-fd255a.png
Snip macro screenshot-fd255a.png (98.16 KiB) Viewed 1327 times
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to use Path.fromShapes ?

Post by onekk »

Russ4262 wrote: Thu Jan 06, 2022 2:09 am ....
Many thanks Russel.

My utilmate goal was Improve my program that will create Gcode to pass to a CNC, so I'm investigating Path creation, with some things in mind:
  • find a way to use a DressUpTags Operation, supplying some relevant point on which i need "holdings Tabs"
  • Script some Engraving operations, maybe using some mathematics to find "groove width" using V-Carve operation, maybe using some sort of height map to compensate for "non planar" engraving surface.
I will very pleased if you find some time to discuss about the DressUpTags thing, as engraving is more a research for now (at least until Spring when I could work in the "non heated" place where I have my CNC under repair).

Best 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