on event: Selected object change

So basically I want to redraw my gui based on what object(s) the user has selected in the 3d window. Even if there were a scriptlink for this, scriptlink scripts don’t allow Draw.Register in them. Is there another event that I don’t know about? Draw.RIGHTMOUSE only works within the active script window, so it doesn’t register when a user clicks in a 3d window.

I’m open to other ideas, so any help would be appreciated.


Seems a reasonable event… join and request on the BfPython ML

this request is not so difficult,

you can use spacehandler scripts to capture events in the 3d window, then perform an action, or even remap keys or mouse presses.

to make your script a spacehandler add the following line to the top:
then you enable it in the view menu of the 3dview window.

to make a spacehandler, see http://www.blender.org/modules/documentation/242PythonDoc/API_related-module.html
and look for “Space Handler Scripts” halfway down the page.

Also have a look at the Window.Qread function example.(which includes the Qadd) to read user inputs. Here’s the link: http://www.blender.org/modules/documentation/242PythonDoc/Window-module.html#QRead

Thanks so much dazzler! I wasn’t aware of the relatively new spacehandler script option. It’s very powerful and I’m sure I’ll end up using it for other things as well.

Space handelers can do a lot but scriptlinks can be good so as not to have python running every move you make. Could also be nice if the new scriptlink worked in with other methods of selection like the oops/outliner.

Good call, ideasman42. I wholeheartedly agree because after exploring the spacehandler script options, it doesn’t appear that I can update the gui of my other script based on an event in the 3d window. I’ll email the BfPython ML as you suggested.

thanks all,

I agree, it would be good to have a scriptlink for this. However, I doubt it will be created right away, so I thought I’d help you brainstorm a solution in the mean time. Could not you just use a spacehandler (or even a scriptlink on redraw) that monitors selection states, and then calls something like Window.RedrawAll()? You could use the registry to store and pass information. I haven’t tested it, and I’m just talking off the top of my head, but I think it should work if it was set up right.