2
$\begingroup$

I am using the method shown in this question to select the size of a text object and drive the size of that object, however I have two text objects in my scene that should be the same size. Is there a way to select the greater of the two and drive both drivers by that value. Is this possible?

$\endgroup$

2 Answers 2

2
$\begingroup$

An update on script from my answer in linked question Any idea how to fit text width to screen

If scene.match_font_width is True it will resize all text in scene to match the one with greatest width. I've put in both an update method on scene.match_font_width and a scene_update handler to make it "live" in the interface. For most applications, I would imagine, the handler is "overkill", as you can just toggle the switch.

Using a driver approach here could result in the dreaded cyclic redundancy check, as the width of t2 is set to t1 (if bigger) that is checking to see if its bigger than t2.

import bpy
from bpy.props import BoolProperty

def set_width(scene):
    if not scene.match_font_width:
        return None

    text_objs = [o for o in scene.objects if o.type == 'FONT']
    max_width = max([o.dimensions.x for o in text_objs])
    for o in text_objs:
        o.dimensions.x = max_width       
        o.scale.y = o.scale.x

    return None

def setwidth(self, context):
    return set_width(self)

bpy.types.Scene.match_font_width = BoolProperty(default=False, update=setwidth)
bpy.app.handlers.scene_update_post.clear()
bpy.app.handlers.scene_update_post.append(set_width)

if True: 
    def match_textwidth(self, context):
        self.layout.prop(context.scene, "match_font_width", toggle=True)

    # for unregister method, hit F8 to clear by reloading scripts.
    #bpy.types.DATA_PT_font.remove(match_textwidth) 

    bpy.types.DATA_PT_font.append(match_textwidth)

If there are some text's you want to resize and others you want left untouched, adding a custom prop to the ones to resize would be one solution

text_objs = [o for o in scene.objects 
             if o.type == 'FONT'
             and "prop" in o.keys()]
$\endgroup$
1
$\begingroup$

Ternary ops duplicate: Is it possible to put an if statement into the scripted expression of a driver?

var if var > x else y

Of course you need two driver and one value

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .