Knife Project in Python?

The Knife Project seems to work only via GUI.

Is there a workaround or addon that implements similar behavior?

I have a polygon in the XY plane. I’d like to project it on the target mesh along Z axis and make a cut on the mesh.

Does bpy.ops.mesh.knife_project not work as expected?

Best wishes,
Matthew

Here is the output from the Python console:

>>> bpy.ops.mesh.knife_project()
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “D:\software\blender-2.69-windows64\2.69\scripts\modules\bpy\ops.py”, line 188, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.mesh.knife_project.poll() failed, context is incorrect

You need to run it in the View 3D context, you can’t directly run it from PyConsole or Text Editor.

http://www.blender.org/documentation/blender_python_api_2_70a_release/info_gotcha.html
http://www.blender.org/documentation/blender_python_api_2_70a_release/bpy.ops.html#overriding-context
http://www.blender.org/documentation/blender_python_api_2_70a_release/info_quickstart.html#operator-poll

I prepared both meshes for the Knife Project and switched to the Edit mode.
I tried to used override in the Python console:


for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = bpy.context.copy()
        override['area'] = area
        bpy.ops.mesh.knife_project(override)

It crashed Blender.

I think somethink else needs to be overriden. Can you suggest what else to override?

HI… Is mandatory use “knife_proyect”??? that don’t work for me in 2.7… but this yes:

bpy.ops.mesh.knife_tool(use_occlude_geometry=True, only_selected=False)



I don’t understant how bpy.ops.mesh.knife_tool can help me to accomplish this task:

I have a polygon in the XY plane. I’d like to project it on the target mesh along Z axis and make a cut on the mesh.

SORRY, let me express this in another way

“knife_proyect” button don’t work for me in any time or proyect… only work for me in knife_tool

also the thing that you want to do is the same like the boolean intersection modifier do (I think so)…

also some add do that (I think so too)… I don’t remember the name… Please give me some time in order to try looking for it…

best

Diego