[Bf-python] on event: Selected object change

Bobby Parker sh0rtwave at gmail.com
Mon Dec 4 15:57:33 CET 2006


I do something along those lines in Neqsus.

Here's what I do.

I have a spacehandler for the 3D window that uses the blender Registry to
store a "changed" variable. The source for it is below. This handler is
included in the main script and initialized upon the first execution of the
script(by initialized, I mean copied into a blender text object). It's not
currently possible to automatically enable the handler, so this is as close
as I could get.



handler = """# SPACEHANDLER.VIEW3D.EVENT
#!BPY

import Blender

evt = Blender.event

if evt == Blender.Draw.RIGHTMOUSE or Blender.Draw.LEFTMOUSE:
    # on a right mouse click assume I've selected an object or unselected it
    # simply set something in the registry to say "hey, something changed"
    changed = { "changed" : True }
    print "changed"
    Blender.Registry.SetKey("BtoR_Space", changed)
    WinID = Blender.Registry.GetKey("BtoR_WinID")
    ID = WinID["ID"][0]
    Blender.Window.QAdd(ID, Blender.Draw.REDRAW, 0, 0)
"""

Breaking it down, this uses Blender.Window.QAdd to add a redraw event to the
window ID identified by BtoR_WinID. This is the ID of the blender script
window...this variable is stuffed into the registry by the primary
script(not the script handler). That's done like this:

        # setup the spaceHandler window ID
        reg = { "ID" : [Blender.Window.GetAreaID()] }
        Blender.Registry.SetKey("BtoR_WinID", reg)

Yell if you need further info.

Bobby AKA ShortWave
sh0rtwave at gmail.com









On 12/3/06, Joel Leineweber <jleineweber at gmail.com> wrote:
>
> I recently brought this up here on blenderartists<http://blenderartists.org/forum/showthread.php?t=83542>, and
> ideasman42 <http://blenderartists.org/forum/member.php?u=6112> suggested I
> email this list for a request.
>
> I basically want a way to redraw my script gui every time the user changes
> the selected object. Even if scriptlinks had this event, they don't allow
> Draw.Register and neither do the (very cool btw) spacehandler scripts.
> Instead it would be useful to have an event handler for object selection
> change (or even other things such as enter/exit editmode, etc.) This will
> allow gui's to become much more responsive to the user and thereby much more
> user-friendly.
>
> thanks for your help & suggestions,
> bydesign
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-python
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20061204/96e81927/attachment.html>


More information about the Bf-python mailing list