Using Blender.Draw in the 3D window...

I’ve just discovered something fun! If you write a script like this:


import Blender
from Blender import Draw
from Blender.BGL import*

def Main():
        obj = Blender.Object.GetSelected()[0]
        name = obj.name

        glColor3f(0,0,0)
        glRasterPos3i(0,0,0)
        Draw.Text(name)

Main()

and then link it to an object in your scene, the Open GL commands are executed in the 3D window, not in the text window! Are there any Gurus out there who know if its possible to get sliders, buttons etc to draw like this? (I can only get it to work with Text). If there is then it means that scripts can be written with an interface in the 3d window itself, i’m thinking of things like sliders for relative vertex keys here, hit this link to see what i mean http://www.projectmessiah.com/x2/messiahanimate.htm

Please tell me this is possible…

I highly doubt it

you may be able to draw them (manually executing gl commands), but they will not respond to mouse stuff unless the api is not … how I would have designed it.

It would probably be worth checking the source, but I doubt the Blender.Draw.Button really creates a real blender button

(oh, and you may want to look and see if they ended up way off somewhere)

I think I am going to try this

It is hard coded into the source that the Draw module will draw to the TextSpace window. I think scripts will run in their own window soon. However, you can’t currently draw to any other windows than the text window.

The Draw module calls the internal blender buttons and sliders for drawing. You should be able to create anything that blender defines as a style, button , menu, slider etc. They have to be defined as UI blocks in the code though.

This is why the draw and bgl modules were written though. So you can design an iterface for a script using blender’s buttons, menus, etc. (You have the full disposal of openGL commands - so theoretically you could do alot more than create some buttons as part of the script interface…)

Hi Flipyneck,

Can u please guide us as to exactly how to link the script to objects and execute it.
Actually, We have got how to link the script but how to finally execute it??

please help!!!

thanking youi

i dunno maybe you can get them to give access to teh new oscreen mod popups liek when you hit the N key while an object is selected

students: download this file for an example.

http://www.flippyneck.com/wip/example.blend

Note that the name of the script is typed into the field for the ‘selected’ link type and ‘redraw’ selected as the option to call the script. If the script is correctly linked then it will work automatically.

I assume it is the script linking that you are interested in rather than drawing to the 3d window. Sadly it seems that at the moment only text can be drawn to the 3d window so no useful script could be created this way. As MacBlender says though, python access to the pop-up windows would be pretty cool…

hey flippyneck,

Thanks a million. We have managed to display Text in the 3d window through Selected Scriptlink.
We wanted to display text in 3d window to begin with & thats exactly what happened :slight_smile:

However, there are 2 options while linking scripts

  1. Selected Scriptlink
  2. Scene Scriptlink

Which one do we use & when?

One more query : Now that we have displayed the text using python scripts, is there any way to capture events like mouse click on this text in the 3d-viewport??
Similar to event capturing on Hyperlinks.

I have tried my hand on event capturing via python, but it only seems to capture events that occur in the text-editor interface.

~ Thanks again