1
$\begingroup$

I have a Python script that changes the text in a blend. In 2.79 the script is:

s = bpy.context.scene
sed = s.sequence_editor
sequences = sed.sequences
f = s.objects['Text']
f.data.body = "New text in the field."

"Text" is the name of the field. This works great.

However, in 2.8 I can use Add Text to do the job of placing the text. However, when I try using the above code, I get:

Traceback (most recent call last):
  File "/home/ec2-user/proj004/proj004master.py", line 27, in <module>
    f = s.objects['Text']
KeyError: 'bpy_prop_collection[key]: key "Text" not found'

I am assuming that since I used Add Text I need to use something other than:

s = bpy.context.scene
sed = s.sequence_editor
sequences = sed.sequences 

Does anybody know how I can make this work?

$\endgroup$
  • 1
    $\begingroup$ s.objects["Text"] is a text object linked to the scene. Since in 2.8 you are using a text strip in VSE ( I assume) there is no font object in scene named "Text", hence the keyerror. So do something other than that. $\endgroup$ – batFINGER Aug 27 at 11:38
  • $\begingroup$ Are you saying there is no way to modify the contents of a text strip using a python script? $\endgroup$ – mcgeo52 Aug 27 at 20:38
0
$\begingroup$

Turns out to be stupid simple:

bpy.context.scene.sequence_editor.sequences_all["Test"].text = "New text in the field."
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.