3
$\begingroup$

I'm trying to visualize assembly of flat pack furniture, out of 2D SVG curves. I can successfully import and extrude the separate SVG paths in Python, conveniently using the path's id to reference the bpy.data.curves[id]:

bpy.ops.import_curve.svg("/path/to/barkruk.svg")
bpy.data.curves["left"].dimensions = "2D"
bpy.data.curves["left"].extrude = 0.003
bpy.data.curves["centert"].dimensions = "2D"
bpy.data.curves["centert"].extrude = 0.003
bpy.data.curves["right"].dimensions = "2D"
bpy.data.curves["right"].extrude = 0.003

(You can find the example SVG at stretchsketch)

I was hoping I could transform (rotate, move) the curves via the rotate_euler properties but these are only present at bpy.data.objects which are not as nice and intuitive reference-able as curves:

>>> bpy.data.objects[3].rotation_euler=(radians(90),0,radians(90))
>>> bpy.data.objects[3].name
'Curve.002'

What is the best approach to rotate a curve in blender 2.77 with Python?

$\endgroup$
  • 1
    $\begingroup$ I am not much into programming at all, but rotating curves in object mode would be the correct way to do it. Not only is it impossible to rotate 2D curves in three dimensions in edit mode (because well they are 2D) it is also not desirable, since they will lose they 2D properties like being closed and capped and cleanly extrudable. Also maintaining them as actual curve objects as long as possible and not converting them to mesh is also preferable because converting to mesh is a destructive one way process. $\endgroup$ – Duarte Farrajota Ramos Jul 25 '16 at 20:07
  • $\begingroup$ Actually this should work, alternatively you can try: bpy.data.objects['BezierCurveName'].rotation_euler. $\endgroup$ – p2or Jul 26 '16 at 8:30
3
$\begingroup$

Test script to import the blender.svg file. As pointed out here the newly added curves are not selected after the import. For convenience added an empty parent.

import bpy
context = bpy.context
scene = context.scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.import_curve.svg(filepath = bpy.app.binary_path.replace(".exe", "") + ".svg")
newcurves = [c for c in context.scene.objects if not c.select]
# deselect all
bpy.ops.object.select_all(action='DESELECT')
# create an empty make it the active  object
empty = bpy.data.objects.new("Holder", None) # use filename maybe
scene.objects.link(empty)
scene.objects.active = empty
empty.select = True
# loop thru the curve objects
for c in newcurves:
    print("Curve: %s", c.name)
    # make it selected
    c.select = True
    # make the parent the empty if not already set
    if not c.parent:
        c.parent = empty
    # change some curve details
    curve = c.data
    curve.dimensions = '2D'
    curve.extrude = 0.003
    # sane object names
    c.name = curve.name
    # location
    #c.location.x += 0.332

empty.scale *= 200

Test on svg enter image description here

If you are going to move and rotate append a call to geometry to origin operator.

bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='BOUNDS')
$\endgroup$
  • $\begingroup$ Thanks a lot! Now I can proceed with animation. You're very welcome to answer possible future questions on that as well :-) $\endgroup$ – dr jerry Jul 31 '16 at 19:29

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.