I am writting a script to import a 2D DXF and turn it into 3D. I have to convert curves into meshes. I manage to do it in Python console but the same Python code in a script has no effect (no errors and curves are not converted).
Here is the code :
import bpy scene = bpy.context.scene # Cleaning the scene bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete(use_global=True) # Importing DXF file bpy.ops.import_scene.dxf('INVOKE_DEFAULT') # if i use Blender GUI #bpy.ops.import_scene.dxf(filepath="/home/liquidus88/model.dxf") #if i do not use Blender GUI (start from terminal) # Converting curves to meshes for obj in scene.objects: scene.objects.active = obj obj.select = True bpy.ops.object.convert(target='MESH') obj.select = False bpy.ops.wm.save_mainfile()
This code work (curves are converted) in these cases:
- I run it in Python console
- I run it as a script without the Blender GUI (in terminal with
blender --background --python script.py)
And does not work (curves are NOT converted) in these cases:
- I run it from Blender text editor with the "Run script" button
- I convert it as an addon and run it by using the addon
I really need to be able to use this code as an addon, any idea why it does not work in the cases i mentioned above ?