realsize.py - problems with menu() [UPDATE]

Hi,

I created a script[1] that helps me to measure distances between vertices and objects. I needed it to create a real live scene. Perhaps someone else think it’s usefull. And if other people like more distances (miles,…) I’ll add them later.

But currently I’ve one big problem with the menus. Everytime I change the menu entry the menu switches back to the default entry. I don’t know why this happen. I created some examples and hadn’t this problem. But I don’t find the problem. Could someone try it and help me with this?

http://brachttal.net/blender/scripts/realsize/

UPDATE:
I made some updates to the script and there’s more functionality now. I think it’s self explaining, but perhaps I’ll create a little readme file how to use it.

regards
Andreas

I ran into this problem too.

The draw() function runs a lot of times during script execution because it got Registered. This happens when you move the mouse around the screen, press buttons and those kinds of things. So the GUI gets redrawn a lot times after you press Alt+P, with exactly what the draw() function says.
Now look at the your unit_menu menu. It says it’s default value should be 0: the km option. When you select an option from the menu, the menu gets set to the value of the option you selected. Apparantely Blender reruns the draw() function when you release the mouse button. So the menu gets reset again to km, instead of the option you selected.
Functions and variables outside the draw() function don’t get rerun. So instead, set the default value of the menu outside of the draw() function. If you just do unit_menu = 0, you might get problems with datatypes or something like that. That’s why Blender has a special function for this: Draw.Create().

So your script will look like this:

#Default button states
unit_menu = Blender.Draw.Create(0)

def draw():
  global unit_menu
  unit_menu = Blender.Draw.Menu(menu_name,EVENT_NOEVENT , 250, 53, 50, 20, unit_menu.val, "Select the measure unit")

Register(draw, event, bevent)

Great, this worked! I’ll update my script and then upload it again.

thanks
Andreas[/quote]