Setting enum properties across multiple interdependent enum properties in a script The Data Transfer modifier offers multiple enum properties which in the interface can be changed with clicking (exclusively sets one value and disables the others) or shift-clicking/dragging (allows to set multiple values).



This behaviour not only affects each of these enum properties on their own, but also reaches across all the other properties, unsetting previously set values in property A if values in set B are set. (To illustrate this, the next image shows the state of the modifier from the previous image after clicking on "UVs" - the values "Sharp" and "UV Seam" are unset in the other enum property)



In the interface, setting multiple values in multiple enum properties is possible through shift-clicking across them, but when scripting the same behaviour I run into a problem:

obj.modifiers["DataTransfer"].data_types_loops_uv = {"UV"}


... does what one expects, and so does - mind the different property being set here (!) ...

obj.modifiers["DataTransfer"].data_types_edges = {"SHARP_EDGE"}


... but the second line also removes the previously set "UV" value on the previous property (!) ...

Lacking shift-click in a script :) and not knowing of a way to set both data_types_loops_uv and data_types_edges in one assignment (and rather wanting to avoid working with multiple DataTransfer modifiers for each property) I am now stuck and would appreciate any help!
The problem is data_types_edges as well as the other data transfer attributes are python set objects and you are overwriting the entire set losing the previous values.

To add an element to a set, us the |= operator.

import bpy

data_transfer = bpy.context.object.modifiers["DataTransfer"]

data_transfer.data_types_edges |= {'SHARP_EDGE'}


It seems that the add() and update() function do not affect the modifier; so just use |= instead.