I have developped an addon and I want to call a few function from command line. Everything works fine except when I'm using knife_project. Here is my code:

region, rv3d, v3d, area = view3d_find(True)
# Define context override dictionary for overriding the knife_project operator's context
override = {
    'scene'            : bpy.context.scene,
    'region'           : region,
    'area'             : area,
    'space'            : v3d,
    'active_object'    : bpy.context.object,
    'window'           : bpy.context.window,
    'screen'           : bpy.context.screen,
    'selected_objects' : bpy.context.selected_objects,
    'edit_object'      : bpy.context.object

# Set view to TOP by directly rotating the 3D view region's view_rotation
rv3d.view_rotation = Euler( (0,0,0) ).to_quaternion()
# Force redraw the scene - this is considered unsavory but is necessary here
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
bpy.ops.mesh.knife_project(override, cut_through=True)

Thing is, I don't have any error in the output log but my mesh is not cut. My guess it's due to:

bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

Do you know if it's possible to use Knife_project in command line ? Or do I have to redo this part of the code to use another function ? (Is there an other function to cut in Blender ?)

Thanks for the help

  • $\begingroup$ Hi. You mention the 'command-line' but you're just using a Python script. Is the script going to be called from the command line? $\endgroup$ – Ray Mairlot May 22 '20 at 15:38
  • $\begingroup$ Hi, yes the script will be called in command line via: blender -b -P /my/script.py $\endgroup$ – Turgal May 25 '20 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.