Need help with fonts and text data script

i need help to make a small script
i got a template file where i need to modify some fields quickly with the today’s date.

let say today’s date is 22 Mars 2019

1 field name = text.057 data = 22 Mars 2019
2 field name = jour1 data = 22
3 field name = mois1 data = 3
4 field name = an1 data = 19

5 field name = dwg-date1 data = 2019

can some one help make a small script to automate the changes for these fields on the template file.
script will be run for now from the text editor.

if possible with a more advance script it would be useful to change
one date field on multiple files in one folder.

thanks for any feedback
happy bl

i can find an object with this

bpy.ops.object.select_pattern(extend=False, pattern=“Cube”, case_sensitive=False)
obj_act = bpy.context.active_object
obj_act.name="smallboxe1

bpy.data.objects[“Object_2”].select = True

I can add some text font like this in 2.8

import bpy

bpy.ops.object.text_add(location=(0, 0, 0), rotation=(0, 0, 0))
txt = bpy.data.objects[‘Text’]
txt.data.body = ‘Testing’
fnt = bpy.data.fonts.load(‘E:\Fonts\FontTTF\crumble.ttf’)
txt.data.font = fnt

and this works fine

thanks
happy bl

looks like there is an error on the font name !

also what it the Text name doing ?

happy bl

got this other faster way but with error in 2.8 for link

yFontCurve = bpy.data.curves.new(type=“FONT”,name=“myFontCurve”)
myFontOb = bpy.data.objects.new(“myFontOb”,myFontCurve)
myFontOb.data.body = “my text”
bpy.context.scene.objects.link(myFontOb)
bpy.context.scene.update()

can someone help to correct this

thanks
happy bl

Try this:

import bpy

myFontCurve = bpy.data.curves.new(type="FONT",name="myFontCurve")
myFontOb = bpy.data.objects.new("myFontOb",myFontCurve)
myFontOb.data.body = "my text"
bpy.context.scene.collection.objects.link(myFontOb)
#bpy.context.scene.objects.link(myFontOb)
bpy.context.scene.update()

Btw you can use this format on discourse to make it easier to copy and paste code.

```
code here
```

to add a new one that is good I guess
but I want to modify an existing one

found this

“”"

sc = bpy.context.scene # Define the scene
ob = sc.objects[‘Text.050’] # Get object named "Text font " in scene
myMesh = ob.data # Transfert the Mesh data to mymesh

ob.data.body = “Jour”

“”"

I get the date with string from time module
but the day is like 03 as a string I think

how do you get this converted to a number
eval does not like that 0

may be get rid of the 0 in the string !

thanks
happy bl

You can use int('03') if the number is an integer.

‘’’

import time

year1 = time.strftime("%Y")
day1 = time.strftime("%d")
month1 = time.strftime("%m")

print ( 'Year = ‘, year1 , ’ Month =’, month1 , ’ day = ', day1 )

print ( 'day = ', day1 )
print ( 'month = ', month1 )

‘’’

this seems to give a string for day month and year
so have to delete the 0 in the string first I guess but how

will try to continue tomorrow getting late here !

thanks
happy bl