SVG v0.5.9o : import path to bezier curve (2009/04/20)

http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_svg_en.htm

SVG 2 OBJ translater, 0.5.9o
(c) jm soler juillet 2004-april 2009, 
    released under GPL
   for the Blender 2.33 to 2.49 Python Scripts Bundle.
#---------------------------------------------------------------------------
# Page officielle :
#   http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_import_svg_en.htm
# Communiquer les problemes et erreurs sur:
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#---------------------------------------------------------------------------

YESSS!!
Can’t wait for it! And four posts for this pack of most useful import-scripts is alright! :wink:
And again, another great script by you!
Thanks in advance.
If you need someone to test it, just tell. I’m on Linux and dabbling around with Gimp and Inkscape … (beg… beg… must have it…)

D.

also, sodipodi, which you can also install in Windows, is a great package and exports SVG :slight_smile: Nice plugin. sodipodi.sourceforge.net

Released a few minutes ago.

CAUTION : this script write a new file with the same name of the imported one but with a .obj extension. If an other file with this name is yet in the same folder it will be erazed.

Wow, this is excellent, excellent, excellent news (along with the EPS import too)!

However, it won’t work for me, trying to open files saved from Adobe Illustrator.

I get this error:

Traceback (most recent call last):
File “<string>”, line 511, in fonctionSELECT
File “<string>”, line 461, in scan_FILE
File “<string>”, line 432, in get_BOUDBOX
File “<string>”, line 426, in get_val
ValueError: empty string for float()

testing file: http://mke3.net/blender/etc/star.svg

Thank for report these errors. I’ll try to correct.

( note :For the moment only path are
avaible and there is no one in this file, just
a polygon shape.)

In gimp 2.02, paths are saved as svg files without extension. One has to add that .

this is the most useful script of the year!

Now, the Gimp 2.0 path are correctly understand and the extension ‘.svg’ is no more needed…

Thanks for this script. However, I can’t use this as I get an error:

Traceback (most recent call last):
File “svg2obj.py”, line 535, in fonctionSELECT
File “svg2obj.py”, line 519, in scan_FILE
File “svg2obj.py”, line 196, in Open_GEOfile
AttributeError: ‘module’ object has no attribute ‘Load’

The script reminds the user not to forget to change the file name then gives the above error. I tried this script with Inkscape and Gimp.

Windows 2000, Blender 233a

gaiamuse

A b234 function, but yet in recent cvs compilation,
note that you can load it yourself, try to find the file
myfileOOO.obj , curves are in.

Thanks jms! I had a chance to test and it works great!

gaiamuse

I need returns about this script from linux user . Does Anybody work with inkscape on linux and make some tests ?

i’m using Linux, and just tried this import plugin.

first tried with some self-made SVGs, exported from Dia, that I use to make UML-diagrams … such as http://an.org/gradu2/mover-original.uml.svg which is about one project with Blender game-engine. importing that fails quietly - nothing is printed to the console, and nothing created in Blender (have both 3d & OOPS views to monitor that). import of another similarily made svg fails reporting:

File “/home/antont/install/blender-2.34-linux-glibc2.2.5-i386/./.blender/scripts/mod_svg2obj.py”, line 559, in format_PATH
D=D.split(’ ')
UnboundLocalError: local variable ‘D’ referenced before assignment

which, reading your source, seems to be a case where find(’ d="') didn’t find anything…?


    if PATH.find(' d="')!=-1:
       PATH,D=get_content('d',PATH)
              
    D=D.split(' ')

Then I tried with some pre-installed Gnome svg icons that were in /usr/share - /usr/share/icons/gnome/scalable/emblems/emblem-cool.svg which fails differently:

File “/home/antont/install/blender-2.34-linux-glibc2.2.5-i386/./.blender/scripts/mod_svg2obj.py”, line 611, in scan_FILE
courbes,n0,CP=Actions[cell]([cell,cursor], D, n0,CP)
File “/home/antont/install/blender-2.34-linux-glibc2.2.5-i386/./.blender/scripts/mod_svg2obj.py”, line 383, in courbe_vers_c
if D[c[1]+4] not in TAGcourbe :
IndexError: list index out of range

Finally I found one svg that worked, in the Inkscape examples, markers.svg . It is created as a nice looking pair of sunglasses, made as a Bezier, in Blender. Some others (at least gradient.svg) fail with that same error (in courbe_vers_c).

Hopefully this report was helpful, and do tell more about what you wish Linux users to test … I think I’ll try saving as .ps from Dia and importing those with this plugin next

~Toni

first of all thanks for your script,
i’ve exported sone svg with an open source software called lx viewer ( http://lx-viewer.sourceforge.net/ ) able to convert dvg and dxf files in svg format.

your scrip doesn’ t seem to work with these files, but maybe you ca have a look at it.

EDIT:
after importing this svg into gimp2.0 and exporting from gimp to svg the script give me this error:

['M', 0] 0.88,0.36
['0.88', '0.36']
Traceback (most recent call last):
  File "C:\Programmi\Blender Foundation\Blender\.blender\scripts\mod_svg2obj.py"
, line 648, in fonctionSELECT
    scan_FILE(nom)
  File "C:\Programmi\Blender Foundation\Blender\.blender\scripts\mod_svg2obj.py"
, line 616, in scan_FILE
    courbes,n0,CP=Actions[cell]([cell,cursor], D, n0,CP)
  File "C:\Programmi\Blender Foundation\Blender\.blender\scripts\mod_svg2obj.py"
, line 388, in courbe_vers_c
    courbe_vers_c(c, D, n0,CP)
  File "C:\Programmi\Blender Foundation\Blender\.blender\scripts\mod_svg2obj.py"
, line 367, in courbe_vers_c
    B.co=[l[4],
IndexError: list index out of range

hope can help

tnx 4 your work

Ok ! I will have a look at it.

This is not a pure path (no path at all in it) svg file. Translated with inkskape
(to export correct path(s) with inskape select all object and do ctrl-shift-c, but
this file gives bad results) it seems to contain shapes in “false” svg format
like path without a z key at end the line .

finally I can export something from coreldraw direct in bezier curve!!!

before: corel (dxf) > qcad (open-save-close) > blender (and modele on the dxf base!!)

corel > inkscape (onpen-save-close) > blender (ready)… :):):slight_smile:

thanks very much … I will test this right now!!!

A correction to inskape 0.4
http://jmsoler.free.fr/util/blenderfile/py/svg2obj.py
copy this new script in the /.blender/scripts/bpymodules folder

in fact, .blender/scripts/bpymodules folder does not exists before blender 2.37