SVG cannot be converted to a sketch

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

SVG cannot be converted to a sketch

Post by chrisb »

As follow-up to https://forum.freecadweb.org/viewtopic.php?f=3&t=50956 I have here an svg file, which was made in Inkscape 1.1. The imported geometry cannot be converted into a sketch. The file contains a circle and nothing else.

To reproduce
- open or import the attached file with mode "SVG as geometry"
- switch to Draft workbench
- select the imported geometry
- apply DraftToSketch

The path is not converted, error message:

Code: Select all

00:15:02  Traceback (most recent call last):
  File "/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Mod/Draft/draftutils/todo.py", line 167, in doTasks
    Gui.doCommand(string)
  File "<string>", line 1, in <module>
  File "/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Mod/Draft/draftmake/make_sketch.py", line 93, in make_sketch
    if not DraftGeomUtils.isPlanar(shape):
  File "/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Mod/Draft/draftgeoutils/geometry.py", line 280, in isPlanar
    n = getNormal(shape)
  File "/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Mod/Draft/draftgeoutils/geometry.py", line 235, in getNormal
    n = getSplineNormal(shape.Edges[0])
  File "/Users/cb/Desktop/FreeCAD.app/Contents/Resources/Mod/Draft/draftgeoutils/geometry.py", line 209, in getSplineNormal
    n.normalize()
Base.FreeCADError: Cannot normalize null vector

00:15:02  ToDo.doTasks, Unexpected error:
<class 'Base.FreeCADError'>
in ['obj0 = Draft.makeSketch(FreeCAD.ActiveDocument.path23, autoconstraints=True)', 'FreeCAD.ActiveDocument.recompute()']
OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22611 (Git)
Build type: Release
Branch: master
Hash: 7eeec7a5990cc786723225ca8de16ca3186545b3
Python version: 3.8.5
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
Attachments
circle_cb.svg
(1.26 KiB) Downloaded 57 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: SVG cannot be converted to a sketch

Post by Kunda1 »

I can reproduce on

Code: Select all

OS: Manjaro Linux (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22665 (Git) AppImage
Build type: Release
Branch: master
Hash: b0d7850406e046f3b7a8cd5da261e7d54df6bd99
Python version: 3.8.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)

Code: Select all

18:22:34  ----------------
18:22:34  GuiCommand: Convert Draft/Sketch
18:22:34  Traceback (most recent call last):
  File "/tmp/.mount_FreeCAIAOwRJ/usr/Mod/Draft/draftutils/todo.py", line 167, in doTasks
    Gui.doCommand(string)
  File "<string>", line 1, in <module>
  File "/tmp/.mount_FreeCAIAOwRJ/usr/Mod/Draft/draftmake/make_sketch.py", line 93, in make_sketch
    if not DraftGeomUtils.isPlanar(shape):
  File "/tmp/.mount_FreeCAIAOwRJ/usr/Mod/Draft/draftgeoutils/geometry.py", line 280, in isPlanar
    n = getNormal(shape)
  File "/tmp/.mount_FreeCAIAOwRJ/usr/Mod/Draft/draftgeoutils/geometry.py", line 235, in getNormal
    n = getSplineNormal(shape.Edges[0])
  File "/tmp/.mount_FreeCAIAOwRJ/usr/Mod/Draft/draftgeoutils/geometry.py", line 209, in getSplineNormal
    n.normalize()
Base.FreeCADError: Cannot normalize null vector

18:22:34  ToDo.doTasks, Unexpected error:
<class 'Base.FreeCADError'>
in ['obj0 = Draft.makeSketch(FreeCAD.ActiveDocument.path23, autoconstraints=True)', 'FreeCAD.ActiveDocument.recompute()']
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: SVG cannot be converted to a sketch

Post by vocx »

chrisb wrote: Fri Oct 09, 2020 10:17 pm ...
- apply DraftToSketch
...
This is a known issue. See Improvements in SVG. The first post has a summary of various issues with SVG.

Unfortunately the code is broken since February or so, when Yorik and Wandererfan each made changes to DraftGeomUtils.py. I think I can revert the changes, but that may break some code in Arch_CurtainWall (or maybe not, somebody needs to test!).

There may be another solution altogether in the importSVG.py module, as mentioned in that thread by mikeprice99.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: SVG cannot be converted to a sketch

Post by chrisb »

It's indeed the same issue, only my testfile is much simpler. Is there already a ticket?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: SVG cannot be converted to a sketch

Post by Chris_G »

The getSplineNormal cannot work for closed edges.
This would be more reliable :

Code: Select all

def getSplineNormal(edge):
    """Find the normal of a BSpline edge."""
    points = edge.discretize(4)
    v1 = points[1] - points[0]
    v2 = points[1] - points[2]
    n = v1.cross(v2)
    if n.Length:
        return n
    return None
But straight splines would still need to get a special treatment.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: SVG cannot be converted to a sketch

Post by vocx »

chrisb wrote: Sat Oct 10, 2020 6:14 am It's indeed the same issue, only my testfile is much simpler. Is there already a ticket?
I did not open a ticket about it because I've had it in my mind for a long time; I opened the thread above precisely to document these issues. Besides, it's not like we have a ton of Draft programmers who can address these tickets. If Yorik doesn't fix it, I'll probably try fixing it at some point.

However, by looking at Kunda's thread (Bugs/Issues Blocking v0.19 Release), I notice that it is issue #4416.

This is one of those problems that I would really like to offer as a bounty. We could offer $500 to somebody to go through the entire SVG code, fix issues, and prepare unit tests, so that regressions can be detected more easily.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: SVG cannot be converted to a sketch

Post by chrisb »

vocx wrote: Sat Oct 10, 2020 5:15 pm This is one of those problems that I would really like to offer as a bounty.
I wouldn't limit it to this issue, although I see your personal interest :) . We should discuss this in Kunda's topic.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
marioalexis
Posts: 124
Joined: Wed Jun 19, 2019 7:44 pm

Re: SVG cannot be converted to a sketch

Post by marioalexis »

This changes solve the problem: https://github.com/FreeCAD/FreeCAD/pull/3954
This can be marked as solved too: https://tracker.freecadweb.org/view.php?id=4416
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: SVG cannot be converted to a sketch

Post by chrisb »

Thanks! I really like to see things fixed from the 0.19-blocking list.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
marioalexis
Posts: 124
Joined: Wed Jun 19, 2019 7:44 pm

Re: SVG cannot be converted to a sketch

Post by marioalexis »

You are welcome.
Just in case, if something goes wrong with the coplanarity test, there is a tolerance parameter in the make_sketch function, the default value of which should be permissive enough.
Post Reply