7
$\begingroup$

I have multiple instances of class LayerSettings(bpy.types.PropertyGroup), which is simply a group of variables. These are stored at the scene level (they're a predefined number, but many of them). My operators work with different instances of the settings depending on which part of the UI they select (one button executes the operator with settings A, another does the same operator with settings B, etc.).

I'd like to pass the reference of the property group to these operators in the UI.

class SM_OT_image_calculator(bpy.types.Operator):

    layer: bpy.props.PointerProperty(type=LayerSettings)

    def execute(self, context):
        # use self.layer...

When I call the following in my panel:

layout.operator(SM_OT_image_calculator.bl_idname, text="Calculate Foreground").layer = layer_settings_arg

It gives me an error: attribute "layer" from "SM_OT_video_calculator" is read-only. I can't find anything in the documentation or in StackExchange on how to assign properties (there's ones for a collection prop, but it has an add function that PointerProps don't). I know hard-coding is an option for each instance, but that's hard to maintain and debug.

Is there a way to pass a reference of a property group instance to an operator, with the UI?

$\endgroup$

1 Answer 1

6
$\begingroup$

Aafter continuing researching, apparently operators can only take basic properties (e.g. string, bool, int, float, collections of the property types just mentioned), and PointerProperties only work if they’re stored within at the scene level (e.g. bpy.types.Scene) or inside a PropertyGroup.

So, short answer, it doesn't seem possible at this point (2.81a).

Anyways, my current workaround is making an EnumProperty on the panel that switches between the different instances of layers. Since the enum is stored at the scene level, all my operators can reference it freely and easily. It’s not as contained as I’d like, but it works.

$\endgroup$
3
  • 2
    $\begingroup$ Is there any info on why this is not supported? It seems this was a conscious choice when PointerProperties were made available to the python side, I am trying to understand why this was not part of that change, it'd seem very useful. $\endgroup$ Jan 13, 2021 at 1:30
  • $\begingroup$ For official info, I haven't seen any. My guess as to why is probably for security and defensive programming reasons. I hadn't posted anything on the dev site, so you could ask there. $\endgroup$ Jan 13, 2021 at 15:00
  • $\begingroup$ You can use context_pointer_set for this: blender.stackexchange.com/questions/203442 $\endgroup$
    – Ray
    Nov 27 at 22:32

You must log in to answer this question.

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