How to remove the first and last characters for selected text in Blender with a script?
$\begingroup$
$\endgroup$
3
-
$\begingroup$ What text? Blender Has a lot of text everywhere. $\endgroup$– Martynas ŽiemysCommented Nov 16, 2022 at 14:37
-
$\begingroup$ for me it sounds a bit like a python, but not a Blender question...maybe elaborate a bit more what you mean? Which text do you mean? $\endgroup$– ChrisCommented Nov 16, 2022 at 15:44
-
$\begingroup$ The text object in Blender $\endgroup$– Samir MamedovCommented Nov 16, 2022 at 17:57
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
Text object's text is stored in object.data.body
so it's quite easy with Python. Let's say you select all the text objects you want to do that to and want to run a script from the text editor:
import bpy
for o in bpy.context.selected_objects:
if o.type == 'FONT':
o.data.body = o.data.body.replace("\"", "")
This removes " by replacing it with an empty string. You could also do exactly what you asked:
import bpy
for o in bpy.context.selected_objects:
if o.type == 'FONT':
o.data.body = o.data.body[1:-1]
See this for info on slicing (the "[1:-1]" part )
And this for more about working with strings