Page MenuHome

Multiple objects - mirror shape keys don't work properly.
Closed, ArchivedPublic

Description

System Information
Operating system: Darwin-20.4.0-x86_64-i386-64bit 64 Bits
Graphics card: AMD Radeon Pro 5500M OpenGL Engine ATI Technologies Inc. 4.1 ATI-4.4.17

Blender Version
Broken: version: 2.92.0, branch: master, commit date: 2021-02-24 16:25, hash: rB02948a2cab44
Worked: (newest version of Blender that worked as expected)

Short description of error
I am working on an add-on for the blendermarket. The tool is for duplicating and mirroring shape keys, but it seems that when select more objects, then it's not working properly. Do you know why?

Exact steps for others to reproduce the error
launch code. select two objects and run script -

on the screenshot you can see selected two objects and then I am trying to click on the button arrow > and then "Duplicate and Mirror L_ >> R_".
when you select only one object, then it works normally as I want, but two or more it causes issues.

[Based on the default startup or an attached .blend file (as simple as possible)]

The script is in the zip file.

Event Timeline

Those operate on the active object. If the problem is that only one object is having its shape keys mirrored, then that's why.

It's not clear what the problem is, though: how is it "not working properly"?

Lukas Bilek (moner) added a comment.EditedMay 30 2021, 9:56 PM

if one object is selected, then it's fine and mirror works. when two objects are selected, then mirror does not work (it does not happen). I am not sure why. (I think it should work)

Oh! That's my bad; I misunderstood what you were doing.

It looks like it matters which cube is active -- if I select them in one order, one gets mirrored, and in the other order, neither gets mirrored.

I don't see anything obviously off with your code, so it does seem like something's wrong here.

Philipp Oeser (lichtwerk) closed this task as Archived.EditedMay 31 2021, 3:22 PM

Shape Key mirroring uses the context object (ED_object_context(C)) - so setting the active object from python is not enough.
But you can override the context to your liking, see https://docs.blender.org/api/master/bpy.ops.html#overriding-context

If you use something like this in your code it will work

override = bpy.context.copy()
override['object'] = ob
bpy.ops.object.shape_key_mirror(override, use_topology=False)

Good luck with the Addon on blendermarket, will close though since this is not a bug.
(of course feel free to comment again if issues persist)

Hi Philip, you are right. This works quite well. Many thanks. I will have to learn more about context then as I am just a beginner with Blender and it's API.