Blender Asked by jacobo on December 7, 2021
I’m trying (desperately) to get the beginning position in space of each line of a text object, but just couldn’t… 🙁 Any help would be wildly appreciated. The positions I’m trying to get to are marked with red crosses in the attachment picture.
The bounding box
Many of the kerning options for the text object are available. IIRC there is another answer (unfindable so far) that uses these to calculate the positions.
Instead I'm going to simply use the bounding box, single first line, 2 lines, 3 lines etc.
The bounding box is the local axis aligned extent of an object, in local coordinates. The box has 8 coordinates, the zeroth coordinate is the front bottom left hand corner. eg (-1, -1, -1)
for default cube Multiplying by objects matrix world gives the global location.
Test script adds an empty at beginning of each line of the text object that has context.
Answer for version 2.8. For 2.7x would use a scene.update()
to rejig for changes to text body.
import bpy
from mathutils import Vector
context = bpy.context
dg = context.evaluated_depsgraph_get()
ob = context.object
mw = ob.matrix_world
text = ob.data.body
lines = text.split("n")
for i, l in enumerate(lines):
ob.data.body = "n".join(lines[:i + 1])
dg.update()
bbox = [Vector(b) for b in ob.bound_box]
bpy.ops.object.empty_add(
location=mw @ bbox[0]
)
Answered by batFINGER on December 7, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP