0
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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)
$\endgroup$
5
  • $\begingroup$ It works, thanks - but is it unpolite to ask why this is necessary? $\endgroup$
    – simone
    Aug 24, 2021 at 19:42
  • $\begingroup$ elaborated in linked answer. $\endgroup$
    – batFINGER
    Aug 24, 2021 at 19:42
  • 1
    $\begingroup$ 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 $\endgroup$
    – simone
    Aug 24, 2021 at 20:03
  • $\begingroup$ 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. $\endgroup$
    – batFINGER
    Aug 24, 2021 at 20:17
  • $\begingroup$ If so, please consider to vote up the answer(s) as well @simone See: blender.stackexchange.com/help/someone-answers $\endgroup$
    – brockmann
    Aug 27, 2021 at 4:10

You must log in to answer this question.

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