0
$\begingroup$

So here is the setup:

My addon requires very specific collection structures and naming conventions. I need to be able to detect if the user has made a change to the scene collection structure, then run some kind of checker.py script with an execute function.

I've seen questions out there like this one, however they only talk about detecting switching between scenes, not changes within a scene's collection structure: How can i detect a scene change from python?

My initial approach within a menu panel looks something like this:

    class BMNFTS_PT_MainPanel(bpy.types.Panel):
        bl_label = "Blend_My_NFTs"
        bl_idname = "PT_MainPanel"
        bl_space_type = 'VIEW_3D'
        bl_region_type = 'UI'
        bl_category = 'Blend_My_NFTs'

        def draw(self, context): [...]

        def execute(self, context):
            magic_scene_detection = bpy. # Some magic scene change detection

            if magic_scene_detection: 
                checker()
                magic_scene_detection = False

    return {'FINISHED'}

My thinking is that the magic_scene_detection variable would somehow equal True if bpy.ops.outliner was called and if any of the ops in this page were used:

https://docs.blender.org/api/current/bpy.ops.outliner.html?highlight=bpy%20ops%20outliner#module-bpy.ops.outliner

With that said, I sort of have two questions:

  1. How do you actively check if a change was made to a the scene (i.e a collection was created, an object was moved, the name of a collection was changed, etc.)? What goes into that magic_scene_detection variable?
  2. Is this the proper approach for a repeatable 'active' checker system? Or is there some other method with invoke I'm unaware of?

Thank you, I appreciate your time

$\endgroup$
1

1 Answer 1

-1
$\begingroup$

I was able to set this persistant function up here with the help of @ Pavan Bhadaja 's comment:

combinations: int = 0

@persistent
def update_combinations(dummy1, dummy2):
    global combinations

    combinations = (get_combinations.get_combinations_from_scene())

    redraw_panel()

bpy.app.handlers.depsgraph_update_post.append(update_combinations)

I can then call it in a panel draw function here:

def draw(self, context):
    layout.label(text=f"Maximum Number Of NFTs: {combinations}")

Haven't tried this yet myself but I believe you can also pass this to an operator and execute function once the operator is called:

class someOperator(bpy.types.Operator):
    bl_idname = 'id.name'
    bl_label = 'Label'
    bl_description = 'Some Operator'
    bl_options = {"REGISTER", "UNDO"}
    def execute(self, context):
        someFunction(combinations)
        return {"FINISHED"}
$\endgroup$

You must log in to answer this question.

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