From 6c951fbb98a5ddb29240c3efc9af4304ab942396 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 10 Aug 2009 11:58:53 +0000 Subject: adding back button evaluation so you can do 1/60, 90*0.1 etc as well as dimension conversion 1km-10cm+4ft Note... - Python3.1 you don't need to add the .0 for divisions anymore (was esp annoying for button eval) - Simple dimension input, imperial mi/yd/ft/in, metric km/m/cm/mm, Later could display these values and have a pref for scene scale, atm it assumes 1BU == 1m. --- release/ui/bpy_ops.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'release') diff --git a/release/ui/bpy_ops.py b/release/ui/bpy_ops.py index aa9bfb460f0..1d79f1a331f 100644 --- a/release/ui/bpy_ops.py +++ b/release/ui/bpy_ops.py @@ -111,3 +111,48 @@ class bpy_ops_submodule_op(object): import bpy bpy.ops = bpy_ops() + + + + +# A bit out of place but add button conversion code here +module_type = type(__builtins__) +import types +mod = types.ModuleType('button_convert') + +import sys +sys.modules['button_convert'] = mod + +def convert(expr): + + def replace(string, unit, scaler): + # in need of regex + change = True + while change: + change = False + i = string.find(unit) + if i != -1: + if i>0 and not string[i-1].isalpha(): + i_end = i+len(unit) + if i_end+1 >= len(string) or (not string[i_end+1].isalpha()): + string = string.replace(unit, scaler) + change = True + # print(string) + return string + + #imperial + expr = replace(expr, 'mi', '*1609.344') + expr = replace(expr, 'yd', '*0.9144') + expr = replace(expr, 'ft', '*0.3048') + expr = replace(expr, 'in', '*0.0254') + + # metric + expr = replace(expr, 'km', '*1000') + expr = replace(expr, 'm', '') + expr = replace(expr, 'cm', '*0.01') + expr = replace(expr, 'mm', '*0.001') + + return expr + +mod.convert = convert + -- cgit v1.2.3