leomoon84
(leomoon84)
February 5, 2014, 10:37pm
1
Hello,
I’m trying to use Blender to simulate a GUI. I’ve imported all the images and using drivers I can move, scale or rotate things around (like a speed gauge or dashboard). There is one other thing I want to do and that is to change a text object using a slider. So when you key the slider from 0 to 10 for example, it will change the text object 0 to 10…
I tried using Python but I can’t figure it out. Any one can help me out?
Thank you.
CoDEmanX
(CoDEmanX)
February 6, 2014, 5:56am
2
Here’s an example, adds a slider to Object data panel for Text objects and supports animation:
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
return context.object.type == 'FONT'
def draw(self, context):
layout = self.layout
text = context.object.data
layout.prop(text, "my_prop")
def text_change_cb(self, context=None):
self.body = str(self.my_prop)
def frame_change_cb(scene):
for ob in scene.objects:
if ob.type == 'FONT':
text_change_cb(ob.data)
def register():
bpy.types.TextCurve.my_prop = bpy.props.IntProperty(
min=1, max=10, default=5,
update=text_change_cb,
subtype='FACTOR',
)
bpy.app.handlers.frame_change_pre.append(frame_change_cb)
bpy.utils.register_class(HelloWorldPanel)
def unregister():
del bpy.types.TextCurve.my_prop
bpy.app.handlers.frame_change_pre.remove(frame_change_cb)
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
leomoon84
(leomoon84)
February 6, 2014, 10:02am
3
Thank you.
Wow I thought it would be MUCH easier than this!