2
$\begingroup$

I'm trying to bind a Mesh Deform modifier to an object, but when I do that via script it creates one, sets the object to deform with (here child). But when I call bind from the script I does not bind it instantly. I have to select another object with the mouse (some scene update or context switch I guess) then the modifier suddenly gets bound.

A scene update does not change the behavior.

parent.modifiers.new(name="MeshDeform1", type='MESH_DEFORM')
parent.modifiers["MeshDeform1"].object = child
bpy.ops.object.meshdeform_bind(modifier="MeshDeform1")

How do I tell Blender to update the new modifier?

Update: When I explicitly set the object as active at the beginning, the user Interface shows the button "unbind" which should mean the modifier is already bound, but actually the modifier does not do it's job. When I now click unbind and bind again it works as expected.

$\endgroup$

1 Answer 1

0
$\begingroup$

bpy.ops.object.meshdeform_bind() is one of those operators that require an override argument to work in a decent way.

Overriding is basically lying to the operator, and in this case we need to lie about what object is currently active: the object the modifier belongs to.

So, the code should look like this:

override = {"object": parent, "active_object": parent, "scene": D.scenes["Scene"]}

parent.modifiers.new(name="MeshDeform1", type='MESH_DEFORM')
parent.modifiers["MeshDeform1"].object = child
bpy.ops.object.meshdeform_bind(override, modifier="MeshDeform1") #override is used here

Short explanation of the override used here:

  • both "object" and "active_object" are used because they're often the same (C.object and C.active_object) and I don't think you can go wrong with using both
  • "scene" needs to be any scene the object is in. If you do not include this and try to bind from another scene, it will not work/refresh.
$\endgroup$

You must log in to answer this question.

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