I'm using python for batch upload and rendering. I need to import many SVGs, resize them and place to required position. Import is OK, curve is named, I can read dimensions, but I can't write new dimensions back. Where I doing mistake? Thanks for help.

maxSize = 0.220
for emboss in embosses:
    emb_name = emboss[:-4]
    loadedSVG = bpy.ops.import_curve.svg(filepath = embossDir + emboss, filter_glob=".svg")
    for obj in bpy.data.objects:
        if obj.tag == False:
            obj.name = emb_name
            obj.tag = True
            bpy.ops.object.select_pattern(pattern = emb_name)
            meshes = bpy.context.selected_objects

            x, y, z = meshes[0].dimensions 

            if x > y:
                needRatio = maxSize / x
            if y > x:
                needRatio = maxSize / y

            # not working code starts

            meshes[0].dimensions.x = x * needRatio
            meshes[0].dimensions.y = y * needRatio
            meshes[0].dimensions.z = z * needRatio

            # not working code ends


To change the dimensions use the scale Vector.

obj.scale *= needRatio

NB: I have a hassle with obj.tag, albeit could be because I am running in UI and not batch mode.

# import blender svg logo blender.svg in app folder 
# (quick hack works on linux)
bpy.ops.import_curve.svg(filepath = bpy.app.binary_path + ".svg")
#the list of all objects with obj.tag = False `
false_tag = [o for o in bpy.data.objects if not o.tag]

gives me an empty list.

However, it appears the importer doesn't return the objects as selected, hence selecting all objects first then running the op and making a list of all unselected objects in the scene gives me the imported svg's curves could be another way to go.

bpy.ops.import_curve.svg(filepath = bpy.app.binary_path + ".svg")
newcurves = [c for c in context.scene.objects if not c.select]

setting select to True on each curve in newcurves removes the need to run bpy.ops.object.select again.

  • $\begingroup$ Thanx, batFINGER, it works. I'm using blender as tool for photo-complicated scenes and this solution is great for me. $\endgroup$ – Jiri Mlnarik Mar 5 '16 at 20:14

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.