0

So I'm trying to do a boolean operation between two objects. Here's how I'm trying to do it.

def engraveText(baseName, textName):
    bpy.ops.object.select_all(action='DESELECT')
    bpy.context.view_layer.objects.active = bpy.context.view_layer.objects[baseName]
    bpy.data.objects[baseName].select_set(True)
    obj = bpy.data.objects[baseName]
    op = obj.modifiers.new(name="bool", type="BOOLEAN")
    op.object = bpy.data.objects[textName]
    op.operation = "DIFFERENCE"
    bpy.ops.object.modifier_apply({"object": obj}, modifier=op.name, apply_as="DATA")

The error I'm getting is :

Traceback (most recent call last):
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2088, in __call__
        return self.wsgi_app(environ, start_response)
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2073, in wsgi_app
        response = self.handle_exception(e)
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2070, in wsgi_app
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1515, in full_dispatch_request
        rv = self.handle_user_exception(e)
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1513, in full_dispatch_request
        rv = self.dispatch_request()
    File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1499, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
    File "/blender_server/src/server.py", line 76, in getEngravedModel
        engraved_path = be.engraveNewModel(base_path, face_path, text)
    File "/blender_server/src/blender_engraver.py", line 106, in engraveNewModel
        engraveText(base_name, text_name)
    File "/blender_server/src/blender_engraver.py", line 93, in engraveText
        bpy.ops.object.modifier_apply({"object": obj}, modifier=op.name, apply_as="DATA")
    File "/usr/lib/python3.7/2.83/scripts/modules/bpy/ops.py", line 199, in __call__
        ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Modifier is disabled, skipping apply

If I'm missing any info please let me know.

Euan
  • 1
  • 2
  • Quite simply cannot apply a disabled modifier. Far better off using https://blender.stackexchange.com/questions/146559/how-do-i-get-a-mesh-data-block-with-modifiers-and-shape-keys-applied-in-blender – batFINGER Aug 19 '21 at 13:31
  • So I should use bmeshs to apply a boolean modifier? – Euan Aug 19 '21 at 13:52
  • Or to_mesh Hard to know, the error message suggests you are using bpy as a python module and running from flask. Can you run the code without applying the modifier and then take a peek in blender? – batFINGER Aug 19 '21 at 14:07
  • So after running it in blender directly it seems that the object I'm trying to select isn't a mesh, rather still a text curve. I'm going to try convert it and see what happens. – Euan Aug 19 '21 at 14:57
  • So after converting it to a mesh the issue still occurs in the python code I run with flask, but not the one I run directly in blender. Could this be an issue with blender running headlessly? – Euan Aug 19 '21 at 15:26
  • After more testing it seems like this is only occurring in the flask environment. Not sure why that would be the case. – Euan Aug 19 '21 at 15:48
  • Another user says that they had to run blender in the background before running the flask server. (https://stackoverflow.com/questions/65685398/bpy-works-in-global-scope-but-not-in-flask-app) Will check this out tomorrow. – Euan Aug 19 '21 at 15:57

1 Answers1

0

So it turns out this error was being caused by the fact the blender code was being run in flask.

I found a solution here : https://stackoverflow.com/questions/65685398/bpy-works-in-global-scope-but-not-in-flask-app

Euan
  • 1
  • 2