mercredi 26 juin 2019

Blender code: Manage texts

Managing text settings on selection
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import bpy

newfont = bpy.data.fonts.load("//FONTS/ariblk.ttf")
Sel = bpy.context.selected_objects
for obj in Sel:
    if obj.type == 'FONT':
        print(obj)
        obj.data.font = newfont
        obj.data.size = 0.5
        obj.data.space_character = 1.4

Removing text parts on selection (a bit tricky but many possibilities)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import bpy

Sel = bpy.context.selected_objects
for obj in Sel:
    if obj.type == 'FONT':
    #remove first 7 characters
        obj.data.body = obj.data.body[7:]
        
    #remove all but 7 first characters
        obj.data.body = obj.data.body[:7]
        
    #remove from 3rd character to 7 from start
        obj.data.body = obj.data.body[:3] + obj.data.body[7:]
        
    #remove first 3 and copy first 7 to the end
        obj.data.body = obj.data.body[3:] + obj.data.body[:7]
        
    #remove first 3 and copy from after first 7 to the end
        obj.data.body = obj.data.body[3:] + obj.data.body[7:]    
    

Rename texts objects by their content (first 10 characters)
1
2
3
4
5
6
import bpy
print("*****************")
print("rename text objects by content")
for ob in bpy.data.objects:
    if ob.type == 'FONT':
        ob.name = ob.data.body[:10]

Aucun commentaire:

Enregistrer un commentaire