How to change text object through python?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Tanmay
Posts: 0
Joined: Tue Jan 24, 2012 6:05 am
Location: India

How to change text object through python?

Post by Tanmay » Sat Feb 18, 2012 3:28 pm

can any1 tell me, how to change the text of a text object through python?
<t-t>

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Mon Feb 20, 2012 12:03 am

Code: Select all

bpy.data.objects["Text"].data.body = "New Text"

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Mon Feb 20, 2012 12:04 am


Tanmay
Posts: 0
Joined: Tue Jan 24, 2012 6:05 am
Location: India

Post by Tanmay » Mon Feb 20, 2012 9:39 am

i want to change the text in the game engine. I tried the code u gave, but it changed the text permanently, but not in the game. I want to change it only during the game.
<t-t>

Baiame
Posts: 0
Joined: Thu Feb 09, 2012 2:35 pm

Post by Baiame » Mon Feb 20, 2012 2:48 pm

Hi Tanmay,

Follow this tutorial (and the other of ianscott888, just search "text" on his channel), it's well explained :)

http://www.youtube.com/watch?v=kcGLyl__QsA

mb
Posts: 0
Joined: Mon Feb 22, 2010 10:20 am

Post by mb » Mon Feb 20, 2012 5:27 pm

Tanmay wrote:i want to change the text in the game engine. I tried the code u gave, but it changed the text permanently, but not in the game. I want to change it only during the game.
In blender 2.62 a text game property is supported.
Add a text object, then in the logic editor select "Add text game property".
You can then set the "Text" property with either a python script or a property actuator.

Tanmay
Posts: 0
Joined: Tue Jan 24, 2012 6:05 am
Location: India

Post by Tanmay » Sat Feb 25, 2012 10:55 am

i got one more way.

Code: Select all

bge.logic.getCurrentScene().objects['TextObject'].text = 'New Text'
[/code]
<t-t>

Post Reply