[Solved ] how to work with panel and poll ?

got this little code snippet but not working well!

I need to execute a function each time there is a change in the selected ob in viewport

how can I pass the result from the poll to the draw function and execute a function
then I can show the results in label may be

import bpy

class HelloWorldPanel(bpy.types.Panel):

    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"
    def poll(cls, context):
        return obs
    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")

        row = layout.row()

        print ('pbs=',obs)

def register():

def unregister():

if __name__ == "__main__":

thanks for feedback

I think you would need a scene update handler for that (scene_update_pre). Then you would have to come up with some detection mechanism, inside your handler script, to determine if the object has changed. But the labels in the draw area will not update until the user mouse over that area.


yes but is not the poll function supposed to do that update ?

did atst and printed as label the len of selected ob
and seem to work
but had to do it inside the draw method

so seems to update ok function of selected ob in viewport

I will try to add my special function
and see if it works well


I don’t think so…for the most part the event system in Blender is still user driven.

just did a simple test and seems to work fine
how I dont’ know!

but values in sub panel seems ok !
and that is good enough I guess

only problem I have
is that the new panel is at bottom of ob property panel
and need to scroll down to seeall lines for vars
anyway to put it at top may be ?


but is not the poll function supposed to do that update ?

No, it determines whether a panel is to be shown or hidden.