0

I am trying to convert an SVG file to a mesh and then extrude it, using Python, with the later goal of converting SVG paths directly (i.e.: without going through a file)

I get as far as converting the closed path to a curve like this - but fail when trying to create an object (last line):

import bmesh

bpy.ops.import_curve.svg(filepath='test.svg') print('path is ', bpy.data.objects['path38'].type) path = bpy.data.objects['path38']

dg = bpy.context.evaluated_depsgraph_get() path = path.evaluated_get(dg)

mesh = path.to_mesh() print(mesh);

this fails:

o = bpy.data.objects.new("myMesh_object", mesh)

which fails with message:

RuntimeError: Error: Can not create object in main database with an evaluated data data-block

So, what's the right way to go from SVG to path to mesh to extruded object?

simone
  • 745
  • 4
  • 14

1 Answers1

1

Make a copy.

Can't use the evaluated mesh, can use the copy

How do I get a mesh data-block with modifiers and shape keys applied in Blender

Example using bezier circle add,

import bpy
from bpy import context

bpy.ops.curve.primitive_bezier_circle_add() path = context.object print('path is ', path.type)

dg = context.evaluated_depsgraph_get() path = path.evaluated_get(dg)

mesh = path.to_mesh() print(mesh);

this fails:

o = bpy.data.objects.new("myMesh_object", mesh.copy()) context.scene.collection.objects.link(o)

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • It works, thanks - but is it unpolite to ask why this is necessary? – simone Aug 24 '21 at 19:42
  • elaborated in linked answer. – batFINGER Aug 24 '21 at 19:42
  • 1
    I read that through before asking - I understand that being evaluated makes things "dirty" and that making a copy somehow "cleans" them, whereas just making them into a mesh doesn't.. But I still don't grasp the underlying logic/reason why. Maybe it's me - I'll try harder. Thanks for all the answers though, this one al all the others I've relied on – simone Aug 24 '21 at 20:03
  • More ephemeral than dirty. An object or mesh data block 's data is saved in the blend. Their evaluations are not. Copy creates a new data block. – batFINGER Aug 24 '21 at 20:17
  • If so, please consider to vote up the answer(s) as well @simone See: https://blender.stackexchange.com/help/someone-answers – brockmann Aug 27 '21 at 04:10