0
$\begingroup$

I am trying to write a quick Python script that loads .SVG sequences placed in one folder, and cleanly joins all the curves that come with it. I managed to load the .SVGs fine, but I am currently still working on joining the curves.

Here's the code I have:

##################
import bpy
import glob
import os  

# path to your folder

importDir = "C:/tmp/silhouette_svg" 
print("Importing all SVG from this directory", importDir)

os.chdir(importDir)

for files in glob.glob("*.svg"):
    print( files, "... imported!" )
    bpy.ops.import_curve.svg(filepath=files)

Blender's Import Curve should come with the joined option, I think.

$\endgroup$
0
$\begingroup$

A quick hack script (not elegant at all) is something like below.

I manage to do these steps: 1) import svg 2) select and join them as one 3) rename it somewhat (not perfect) 4) turn each one into mesh (for remove doubles?)

############# IMPORTING ALL SVG WITH SEGMENTED
import bpy
import glob
import os  

# path to your folder

importDir = "C:/tmp/silhouette_svg" 
print("Importing all SVG from this directory", importDir)

os.chdir(importDir)

for files in glob.glob("*.svg"):
  print( files, "... imported!" )
  bpy.ops.import_curve.svg(filepath=files)

  # deselect nothing, select all curves, join
  bpy.ops.object.select_all(action='DESELECT')
  bpy.ops.object.select_by_type(type='CURVE')
  bpy.context.scene.objects.active = bpy.data.objects["Curve"]
  for obj in bpy.context.scene.objects:
    if obj.select:obj.name = "snail.000"
  bpy.ops.object.join()
  bpy.ops.object.convert(target='MESH')
  bpy.ops.object.select_all(action='DESELECT')

Any suggestions to make the code more elegant?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.