2
$\begingroup$

I try to import a SVG file into Blender, edit the imported curves dependent on the filename of the SVG and export it after that via Python script.

For example: Importing the first file from a folder named "File_S10.svg" and scale curve by 10 (according to the part "S10" from the file name).

So the question: Is it possible to read the names of a couple of imported SVG files via script?

Any help would be appreciated.

$\endgroup$
1
  • $\begingroup$ The SVG importer does not name imported curve objects according to the files from which they were imported. It doesn't save the filename anywhere else as far as I know. So, if you imported using the blender UI, the answer would be no. You can, however, import directly from the script instead of the UI, then you will necessarily have the file path to do with as you please. $\endgroup$
    – TLousky
    Mar 24, 2016 at 10:14

1 Answer 1

3
$\begingroup$

Using a python script you can specify the svg file to import. After the import you can identify the curves added and adjust their names and properties to match the filename used.

As importing an svg file can create multiple curve objects I would start by making a copy of the existing objects list, then import, then compare the current objects list to the starting list to find what was added during the import.

import bpy
import os

svg_files = [f for f in os.listdir('svgtest') if f.endswith('.svg')]

for f in svg_files:
    start_objs = bpy.data.objects[:]
    bpy.ops.import_curve.svg(filepath=os.path.join('svgtest',f))
    new_curves = [o for o in bpy.data.objects if o not in start_objs]

    n = f[:-8] # the start of the filename
    s = float(f[-6:-4]) # the scale factor as in the 99 from name_S99.svg
    for obj in new_curves:
        obj.name = n
        obj.scale = (s,s,s)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .