Import SVG and Convert to Sketch

A place to share learning material: written tutorials, videos, etc.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Import SVG and Convert to Sketch

Post by TheMarkster »

Any (relatively simple) image can be imported into FreeCAD and converted into a 3d object. The first step is to convert the image into SVG format. There is an online tool free to use that seems to work very well:

https://image.online-convert.com/convert-to-svg

You can upload your image to their server or you can copy/paste the url to the image, and then download the converted file. Once you have the SVG file it's simple to import it into FreeCAD. First, create a new document, then select Import from the File menu, select your SVG file, and choose to import it as geometry (not as a drawing). You will get a number of objects from this import.

Select all the objects and go to the Draft workbench. Choose the make sketch tool, which will (if all goes well) produce multiple sketches (one from each of the objects produced during the SVG import). You can hide (or delete) all of the original import objects. Now select all the different sketches and go to the Sketcher workbench. From the Sketch menu select the merge sketches tool. You can then delete all the other sketches that were produced in the previous step.

Now you have a single sketch comprised mostly of bsplines with a lot (a lot) of degrees of freedom. It will not be really feasible to do much editing with that sketch, but you can extrude it in Part workbench, or apply Part Design features to this sketch quite easily in most cases.
svg_import_example.gif
svg_import_example.gif (920.92 KiB) Viewed 83992 times
We can also use the Curves workbench (You must install the Curves workbench via the Tools -> Addon Manager.) to map the SVG imported sketch to the surface of a cylinder. I have a macro here:

https://github.com/mwganson/SvgToCylinder

that automates this process, creates a cylinder of the appropriate size, and extrudes the curved sketch. Unfortunately, the solids produced from the curved sketch are often invalid. This is because we have to choose a direction for the extrude process and, no matter which direction we pick, a highly curved shape will intersect itself at some point along the way. The direction chosen in the macro is based on the center of gravity of the shape being extruded, but with long shapes this is still problematic. SVG files comprised of individual small shapes will work better than SVG files comprised of larger shapes. For example, an image of a bunch of small balloons will work better than one big balloon.

Here is an animated gif of a butterfly image import using the macro:
svg_import_example2-opt.gif
svg_import_example2-opt.gif (1001.53 KiB) Viewed 83992 times
Some (many) of the sketches produced (lots of b-splines) will be too much for the Sketcher editor to deal with, but can still be extruded or padded, and additional sketches used to modify the model.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Import SVG and Convert to Sketch

Post by chrisb »

Thanks for the report. I would like to add two points:
- If you use inkscape for the conversion you can simplify the path there.
- As you said, you get a lot of points and bsplines. Thus it might be sensible not to put it all in one sketch.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Import SVG and Convert to Sketch

Post by microelly2 »

chrisb wrote: Tue Jul 10, 2018 9:47 pm - As you said, you get a lot of points and bsplines. Thus it might be sensible not to put it all in one sketch.
There is a need to have simplification methods to reduce the number of points in a path/wire without to big changes in geometry.
There are some tasks like
find segments where the points belong nearly to an arc
find segments where the poinbts belong nearly to a line etc ...
I did some work into this direction, but at them moment I have other priorities.
Some suggestions:
https://youtu.be/QXEPoVpmIiI
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Import SVG and Convert to Sketch

Post by TheMarkster »

Made some fixes to the macro. This thing is sweet. See the new animated .gif at the github site (too big for here).

https://github.com/mwganson/SvgToCylinder
User avatar
BarnieO
Posts: 6
Joined: Sun Jul 08, 2018 3:01 pm

Re: Import SVG and Convert to Sketch

Post by BarnieO »

Thanks for sharing. Really useful
PlaneAnimal
Posts: 13
Joined: Tue Oct 30, 2018 2:52 am

Re: Import SVG and Convert to Sketch

Post by PlaneAnimal »

Hello everyone,
This is indeed a very useful ability. But the fine print "will not be really feasible to do much editing with that sketch" . :cry:
I was hoping to use this quick sketch start ability to simplify creating geometry. For example, using a software such as Inkscape to turn
an line art into vectors, export as svg and then import into FreeCAD and make a 3D object from it. I tried and could not make it work.
mind you I'm completely new to FreeCAD so that doen't help. Does anyone have another method ?

Thank you
Post Reply